0.1.0 • Published 11 months ago

esbuild-plugin-esm-cjs-shim v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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.

Noteworthy libs

0.1.0

11 months ago

0.0.2

11 months ago