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

0.2.3 • Public • Published

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: https://github.com/finom/babel-plugin-transform-es2015-modules-simple-amd/pull/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.

Readme

Keywords

Package Sidebar

Install

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

Weekly Downloads

2

Version

0.2.3

License

MIT

Unpacked Size

15.4 kB

Total Files

5

Last publish

Collaborators

  • augusts-karklins