0.19.0 • Published 5 years ago

babel-plugin-transform-es2015-modules-reify v0.19.0

Weekly downloads
89
License
MIT
Repository
github
Last release
5 years ago

babel-plugin-transform-es2015-modules-reify

This plugin transforms ES2015 module syntax to code that uses the Reify runtime API.

Benefits of this transform include:

  • Imported variables are never renamed or turned into property lookups, so you can inspect your imports easily in the debugger.

  • Nested import declarations are supported.

  • Live bindings are simulated by automatically updating imported variables whenever new values are exported.

How it works

Please see the Reify README.md file for more details about how the runtime API works.

Installing the plugin

npm install --save-dev babel-plugin-transform-es2015-modules-reify
npm install --save reify

Installing the runtime

Node

In Node, you can install the Module.prototype.{watch,export,runSetters} API simply by calling require("reify/node").

Other module systems

Using Reify with other CommonJS module systems is possible, but not always easy. In order to work with Reify, the module system must

  • Have a Module.prototype object that all CommonJS module objects inherit from, or at least a hook for adding Reify's runtime methods to each module object.

  • Implement a Module.prototype.resolve(id) method that returns the same absolute module identifier string as require.resolve(id). No longer a requirement thanks to the module.watch(require(id), ...) API!

  • Call module.runSetters() whenever a module finishes evaluating, even if it was not compiled by Reify.

If your module system meets these requirements, then you can install the Reify runtime by calling

require("reify/lib/runtime").enable(module)

for each module object. If your module system has a Module.prototype object, then you only need to call this function once:

require("reify/lib/runtime").enable(module.constructor.prototype)

Note that module.constructor is an easy way to refer to the Module constructor.

You can see how the Node runtime meets these requirements here.

You can see how Meteor meets these requirements via the install npm package here and here.

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["transform-es2015-modules-reify"]
}

Via CLI

babel --plugins transform-es2015-modules-commonjs script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-es2015-modules-commonjs"]
});
0.19.0

5 years ago

0.18.0

6 years ago

0.17.0

6 years ago

0.16.0

6 years ago

0.15.1

6 years ago

0.15.0

6 years ago

0.14.2

6 years ago

0.14.1

6 years ago

0.14.0

6 years ago

0.13.3

6 years ago

0.13.2

6 years ago

0.13.1

6 years ago

0.13.0

6 years ago

0.12.4

7 years ago

0.12.3

7 years ago

0.12.2

7 years ago

0.12.1

7 years ago

0.12.0

7 years ago

0.11.2

7 years ago

0.11.1

7 years ago

0.11.0

7 years ago

0.10.0

7 years ago

0.9.0

7 years ago

0.8.0

7 years ago

0.7.0

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.5.1

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.6

7 years ago

0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago