Home

Awesome

esmify

A dead-simple tool to add import / export ES Module syntax to your browserify builds.

The plugin makes the following changes to your bundler:

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

browserify index.js -p esmify > bundle.js

Also works with budo and similar tools, for example:

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 to install.

npm install esmify --save-dev

Also can be used via API like so:

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

Usage

plugin = esmify(bundler, opt = {})

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

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 and browser-resolve.

Works like so:

License

MIT, see LICENSE.md for details.