Skip to content

Instantly share code, notes, and snippets.

@sidwebworks
Created November 18, 2021 11:54
Show Gist options
  • Save sidwebworks/eab66b17ffff135a246e2cb38d259696 to your computer and use it in GitHub Desktop.
Save sidwebworks/eab66b17ffff135a246e2cb38d259696 to your computer and use it in GitHub Desktop.
Basic template for esbuild javascript api plugin
import * as esbuild from "esbuild-wasm"
export const unpkgPathPlugin = () => {
return {
name: "unpkg-path-plugin",
setup(build: esbuild.PluginBuild) {
build.onResolve({ filter: /.*/ }, async (args: any) => {
console.log("onResole", args)
return { path: args.path, namespace: "a" }
})
build.onLoad({ filter: /.*/ }, async (args: any) => {
console.log("onLoad", args)
if (args.path === "index.js") {
return {
loader: "jsx",
contents: `
import message from './message';
console.log(message);
`,
}
} else {
return {
loader: "jsx",
contents: 'export default "hi there!"',
}
}
})
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment