esbuild-plugin-esm-cjs-shim
v0.1.0
Published
Shims ESM and CJS features, handy if you are building hybrid NPM modules.
Downloads
1
Readme
esbuild-plugin-esm-cjs-shim
Shims ESM and CJS features, handy if you are building hybrid NPM modules.
Features
Shims when building ESM:
- __filename
- __dirname
- require (require.resolve)
Shims when building CJS:
- import.meta.url
Getting Started
npm install esbuild-plugin-esm-cjs-shim
Load plugin
const { shimPlugin } = require("esbuild-plugin-esm-cjs-shim)";
or if ESM:
import { shimPlugin } = from "esbuild-plugin-esm-cjs-shim";
Add following to your esbuild-conf:
{
entryPoints: ["./commonjs.entry.js"],
bundle: true,
write: false,
+ plugins: [shimPlugin()],
+ format: "esm", // or "cjs" depending on what you need to build
+ platform: "node",
};
Known issues
- All shims are included at this point.
Credits
Idea from tsup, the primary reason for this lib is to create a separate esbuild-plugin.
- https://github.com/egoist/tsup/
Noteworthy libs
- https://www.npmjs.com/package/babel-plugin-transform-import-meta