# esbuild-plugin-esm-cjs-shim

> Shims ESM and CJS features, handy if you are building hybrid NPM modules.

Latest version **0.1.0** (published 2023-06-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install esbuild-plugin-esm-cjs-shim
pnpm add esbuild-plugin-esm-cjs-shim
yarn add esbuild-plugin-esm-cjs-shim
bun add esbuild-plugin-esm-cjs-shim
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2023-06-11 |
| First published | 2023-06-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >= 14.0 |
| Dependencies | 0 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Olof |
| Maintainers | oloff |

## Links

- npm: https://www.npmjs.com/package/esbuild-plugin-esm-cjs-shim
- Repository: https://github.com/OlofFredriksson/esbuild-plugin-esm-cjs-shim
- Homepage: https://github.com/OlofFredriksson/esbuild-plugin-esm-cjs-shim#readme
- Issues: https://github.com/OlofFredriksson/esbuild-plugin-esm-cjs-shim/issues
- npm.io page: https://npm.io/package/esbuild-plugin-esm-cjs-shim

## Recent versions

- 0.1.0 (latest) — 2023-06-11
- 0.0.2 — 2023-06-06

## 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

```javascript
const { shimPlugin } = require("esbuild-plugin-esm-cjs-shim)";
```

or if ESM:

```javascript
import { shimPlugin } = from "esbuild-plugin-esm-cjs-shim";
```

Add following to your esbuild-conf:

```diff
{
    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

---
_Source: https://npm.io/package/esbuild-plugin-esm-cjs-shim · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
