# esmify

> parse and handle import/export for browserify

Latest version **2.1.1** (published 2019-01-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install esmify
pnpm add esmify
yarn add esmify
bun add esmify
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2019-01-28 |
| First published | 2018-03-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 11.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 119 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | browserify, es, esm, es6, import, export, require, commonjs, umd, cjs, es2015 |

## Links

- npm: https://www.npmjs.com/package/esmify
- Repository: https://github.com/mattdesl/esmify
- Issues: https://github.com/mattdesl/esmify/issues
- npm.io page: https://npm.io/package/esmify

## Dependencies (10)

- [through2](https://npm.io/package/through2.md) ^2.0.5
- [duplexer2](https://npm.io/package/duplexer2.md) ^0.1.4
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.2.2
- [concat-stream](https://npm.io/package/concat-stream.md) ^1.6.2
- [cached-path-relative](https://npm.io/package/cached-path-relative.md) ^1.0.2
- [babel-plugin-import-to-require](https://npm.io/package/babel-plugin-import-to-require.md) ^1.0.0
- [@babel/plugin-syntax-dynamic-import](https://npm.io/package/@babel/plugin-syntax-dynamic-import.md) ^7.2.0
- [@babel/plugin-syntax-async-generators](https://npm.io/package/@babel/plugin-syntax-async-generators.md) ^7.2.0
- [@babel/plugin-syntax-object-rest-spread](https://npm.io/package/@babel/plugin-syntax-object-rest-spread.md) ^7.2.0
- [@babel/plugin-transform-modules-commonjs](https://npm.io/package/@babel/plugin-transform-modules-commonjs.md) ^7.2.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 2.1.1 (latest) — 2019-01-28
- 2.1.0 — 2019-01-28
- 2.0.0 — 2018-10-19
- 1.2.0 — 2018-07-31
- 1.1.0 — 2018-07-11
- 1.0.4 — 2018-07-10
- 1.0.3 — 2018-07-10
- 1.0.1 — 2018-07-10
- 1.0.0 — 2018-07-10
- 0.1.2 — 2018-07-09
- 0.1.1 — 2018-05-19
- 0.1.0 — 2018-03-14

## README

# esmify

A dead-simple tool to add `import` / `export` ES Module syntax to your [browserify](https://www.npmjs.com/package/browserify) builds.

The plugin makes the following changes to your bundler:

- Adds `.mjs` extension to module resolution (which take precedence over `.js` files)
- Resolves to `"module"` field in `package.json` when a `"browser"` field is not specified
- Transforms ES Module syntax (static `import` / `export` statements) into CommonJS

Use it with the `--plugin` or `-p` flags in browserify:

```js
browserify index.js -p esmify > bundle.js
```

Also works with [budo](https://www.npmjs.com/package/budo) and similar tools, for example:

```js
budo index.js --live -- -p esmify
```

Files that don't contain `import` / `export` syntax are ignored, as are dynamic import expressions. The plugin runs across your bundle (including `node_modules`) in order to support ESM-authored modules on npm.

## Install

Use [npm](https://npmjs.com/) to install.

```sh
npm install esmify --save-dev
```

Also can be used via API like so:

```js
browserify({
  plugin: [
    [ require('esmify'), { /* ... options ... */ } ]
  ]
});
```

## Usage

#### `plugin = esmify(bundler, opt = {})`

Returns a browswerify plugin function that operates on `bundler` with the given options:

- `mainFields` which describes the order of importance of fields in package.json resolution, defaults to `[ 'browser', 'module', 'main' ]`
- `nodeModules` (default `true`) to disable the transform on your `node_modules` tree, set this to `false`. This will speed up bundling but you may run into issues when trying to import ESM-published code from npm.
- `plainImports` (Experimental) this feature will map named imports *directly* to their CommonJS counterparts, without going through Babel's inter-op functions. This is generally needed for static analysis of `fs`, `path` and other tools like `glslify` in browserify. Defaults to `[ 'fs', 'path', 'glslify' ]`.

Under the hood, this uses Babel and `plugin-transform-modules-commonjs` to provide robust inter-op that handles a variety of use cases.

#### `require('esmify/resolve')(id, opts, cb)`

Resolve the given `id` using the module resolution algorithm from `esmify`, accepting `{ mainFields }` array to opts as well as other options passed to [resolve](https://www.npmjs.com/package/resolve) and [browser-resolve](https://www.npmjs.com/package/browser-resolve).

Works like so:

- If mainFields includes a `"browser"` field, use `browser-resolve`, otherwise use `resolve`
- Look for package.json fields in order of `mainFields`, the first field that exists will be used

## License

MIT, see [LICENSE.md](http://github.com/mattdesl/esmify/blob/master/LICENSE.md) for details.

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