Babel plugin for transforming ES2015 import/export to Reify's module.{import,export} API
npm install babel-plugin-transform-es2015-modules-reifyThis 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.
Please see the ReifyREADME.md file for more
details about how the runtime API works.
``sh`
npm install --save-dev babel-plugin-transform-es2015-modules-reify
npm install --save reify
Node
In Node, you can install the Module.prototype.{watch,export,runSetters}require("reify/node")
API simply by calling .
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 objectsmodule
inherit from, or at least a hook for adding Reify's runtime methods to
each object.
* ~~Implement a Module.prototype.resolve(id) method that returns therequire.resolve(id)
same absolute module identifier string as .~~ Nomodule.watch(require(id), ...)
longer a requirement thanks to the 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
`js`
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:
`js`
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.
.babelrc
`js`
{
"plugins": ["transform-es2015-modules-reify"]
}
`sh`
babel --plugins transform-es2015-modules-commonjs script.js
`javascript``
require("babel-core").transform("code", {
plugins: ["transform-es2015-modules-commonjs"]
});