Giter Site home page Giter Site logo

babel-plugin-add-module-exports's Introduction

babel-plugin-add-module-exports

Installation

npm install babel-plugin-add-module-exports --save-dev

Why?

Babel@6 doesn't export default module.exports any more - T2212 Kill CommonJS default export behavior.

Babel@6 transforms the following file

// index.js
export default 'foo'

into

'use strict';
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = 'foo';

Therefore, it is a need to use the ugly .default in node.js.

require('./bundle.js') // { default: 'foo' }
require('./bundle.js').default // 'foo'

This plugin follows the babel@5 behavior - add the module.exports if only the export default declaration exists.

'use strict';
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = 'foo';
module.exports = exports['default'];

Therefore, our old codes still work fine - the .default goes away. ๐Ÿ˜‰

require('./bundle.js') // foo

Usage

Install this plugin from npm:

npm install babel-plugin-add-module-exports --save-dev

Write the name to babelrc. It works with preset-es2015 to output CommonJS code:

{
  "presets": ["es2015"],
  "plugins": [
    "add-module-exports"
  ]
}

It also works with transform-es2015-modules-umd plugin to output UMD code: (It is a must to place UMD plugin after this plugin.)

{
  "presets": ["es2015"],
  "plugins": [
    "add-module-exports",
    "transform-es2015-modules-umd"
  ]
}

License

MIT

babel-plugin-add-module-exports's People

Contributors

59naga avatar lijunle avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.