@babel/plugin-transform-modules-amd
History
Version | Changes |
---|---|
v7.14.0 | Implemented the importInterop option |
NOTE: This plugin is included in
@babel/preset-env
under themodules
option
This plugin transforms ECMAScript modules to AMD. Note that only the syntax of import/export statements (import "./mod.js"
) and import expressions (import('./mod.js')
) is transformed, as Babel is unaware of the different resolution algorithms between implementations of ECMAScript modules and AMD.
Example
In
JavaScript
export default 42;
Out
JavaScript
define(["exports"], function(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.default = 42;
});
Installation
- npm
- Yarn
npm install --save-dev @babel/plugin-transform-modules-amd
yarn add --dev @babel/plugin-transform-modules-amd
Usage
With a configuration file (Recommended)
babel.config.json
{
"plugins": ["@babel/plugin-transform-modules-amd"]
}
Via CLI
Shell
babel --plugins @babel/plugin-transform-modules-amd script.js
Via Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-transform-modules-amd"],
});
Options
See options for @babel/plugin-transform-modules-commonjs
.