@babel/plugin-transform-modules-amd

NOTE: This plugin is included in @babel/preset-env under the modules 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

  1. export default 42;

Out

  1. define(["exports"], function(exports) {
  2. "use strict";
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true,
  5. });
  6. exports.default = 42;
  7. });

Installation

  1. npm install --save-dev @babel/plugin-transform-modules-amd

Usage

  1. {
  2. "plugins": ["@babel/plugin-transform-modules-amd"]
  3. }

Via CLI

  1. babel --plugins @babel/plugin-transform-modules-amd script.js

Via Node API

  1. require("@babel/core").transformSync("code", {
  2. plugins: ["@babel/plugin-transform-modules-amd"],
  3. });

Options

See options for @babel/plugin-transform-modules-commonjs.