Skip to content

AugustsK/babel-plugin-transform-modules-simple-amd

 
 

Repository files navigation

babel-plugin-transform-modules-simple-amd-with-default-exports npm version

Limited transformer for ECMAScript 2015 (and beyond) modules into simplified AMD format.

Converts this code:

import x from '/path/to/x';
import y from '/path/to/y';
doSomething();
export default x + y;

Into this one:

define(['/path/to/x', '/path/to/y'], function (x, y) {
  doSomething();
  return x + y;
});

Instead of this one (generated with @babel/plugin-transform-modules-amd):

define(['exports', '/path/to/x', '/path/to/y'], function (exports, _x, _y) {
  Object.defineProperty(exports, "__esModule", {
    value: true
  });

  var _x2 = _interopRequireDefault(_x);

  var _y2 = _interopRequireDefault(_y);

  function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
      'default': obj
    };
  }

  doSomething();
  exports.default = _x2.default + _y2.default;
});

Forked from this PR that never got merged in: finom#10

Installation

$ npm install -D babel-plugin-transform-modules-simple-amd-with-default-exports

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["babel-plugin-transform-modules-simple-amd-with-default-exports"]
}

Via Node API

require('babel').transform('code', {
  plugins: ['babel-plugin-transform-modules-simple-amd-with-default-exports']
});

The same thing for CommonJS.

Thanks to finom and dcleao.

About

Limited transformer for ECMAScript 2015 modules (AMD)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%