Skip to content

Instantly share code, notes, and snippets.

@danny-andrews
Created August 24, 2022 18:49
Show Gist options
  • Select an option

  • Save danny-andrews/375f5d393f0de02b164fd3ae3b0e248d to your computer and use it in GitHub Desktop.

Select an option

Save danny-andrews/375f5d393f0de02b164fd3ae3b0e248d to your computer and use it in GitHub Desktop.

Revisions

  1. danny-andrews created this gist Aug 24, 2022.
    19 changes: 19 additions & 0 deletions loader.mjs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    import esbuild from "esbuild";
    import { readFile } from "node:fs/promises";
    import { fileURLToPath } from "node:url";

    export async function load(url, context, nextLoad) {
    const source = await readFile(fileURLToPath(url), "utf-8");

    if (/\.jsx$/.test(url)) {
    const transformedSource = await esbuild.transform(source, {
    loader: "jsx",
    });
    return {
    format: "module",
    source: transformedSource.code,
    };
    }

    return nextLoad(url, context);
    }