Package Exports
- babel-plugin-add-module-exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-plugin-add-module-exports) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
babel-plugin-add-module-exports
Installation
npm install babel-plugin-add-module-exports --save-dev
Why?
babel-plugin-transform-es2015-modules-commonjs@6.1.4 doesn't support the module.exports
.
// index.js
export default 'foo'
npm install babel-cli --global
npm install babel-preset-es2015 --save-dev
npm install babel-plugin-transform-es2015-modules-commonjs@6.1.4 --save-dev
babel index.js --presets es2015 --plugins transform-es2015-modules-commonjs > bundle.js
# 'use strict';
#
# Object.defineProperty(exports, "__esModule", {
# value: true
# });
# exports.default = 'foo';
Therefore, need to use the .default
at NodeJS.
require('./bundle.js') // { default: 'foo' }
require('./bundle.js').default // 'foo'
This plugin add the module.exports
if only the export default
declaration exists.
npm install babel-plugin-add-module-exports --save-dev
babel index.js --presets es2015 --plugins add-module-exports > bundle.js
# 'use strict';
#
# Object.defineProperty(exports, "__esModule", {
# value: true
# });
# exports.default = 'foo';
# module.exports = exports['default'];
Therefore, .default
is the unnecessary.
require('./bundle.js') // foo