A plugin for esbuild to shim imports for commonjs and esm modules.
npm install esbuild-shim-plugin



_esbuild-shim-plugin_ is an esbuild plugin that polyfills support for the import.meta.url property for ESM modules and the require, __filename, and __dirname properties for CommonJS modules.
``sh`
pnpm i -D esbuild-shim-plugin
`typescript
import { build } from 'esbuild';
import { shimPlugin } from 'esbuild-shim-plugin';
await build({
format: 'esm',
plugins: [shimPlugin()],
// ... rest of the configuration
});
`
###### With tsup configuration
`typescript
import { shimPlugin } from 'esbuild-shim-plugin';
import { defineConfig } from 'tsup';
export default defineConfig([
{
format: ['cjs', 'esm'],
esbuildPlugins: [shimPlugin()],
// ... rest of the configuration
},
]);
``
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub.
Thanks again for your support, it is much appreciated! 🙏
- ESBuild
- EMCAScript Modules
- CommonJS Modules
MIT © Shahrad Elahi and contributors.