Previously, all "bare imports" (e.g. `import './foo';`) were moved to the end of the array of sources. I presume this was done to remove needless variables in the callback signature. Unfortunately, doing this actually changes the intent of the program. Modules should be evaluated in the order that they were in the source. In the case of a bare import, it is quite possible that the bare import has side effects that a later required module should see. With the current implementation the later imported modules are evaluated before that "side effecty" module has been evaluated. Obviously, it is better to avoid these sorts of side effect ridden modules but even still you could imagine a similar issue with cycles. This change ensures that module source order is preserved in the AMD dependencies list, and avoids making needless variables as much as possible.
babel-plugin-transform-es2015-modules-amd
This plugin transforms ES2015 modules to Asynchronous Module Definition (AMD).
Example
In
export default 42;
Out
define(["exports"], function (exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = 42;
});
Installation
npm install --save-dev babel-plugin-transform-es2015-modules-amd
Usage
Via .babelrc (Recommended)
.babelrc
{
"plugins": ["transform-es2015-modules-amd"]
}
Via CLI
babel --plugins transform-es2015-modules-amd script.js
Via Node API
require("babel-core").transform("code", {
plugins: ["transform-es2015-modules-amd"]
});
Options
See options for babel-plugin-transform-es2015-commonjs.