Created
November 18, 2021 11:54
-
-
Save sidwebworks/eab66b17ffff135a246e2cb38d259696 to your computer and use it in GitHub Desktop.
Basic template for esbuild javascript api plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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