Babel 6 no longer transform export default
like babel 5
From var a = require('./a');
to var a = require('./a').default;
See [Repo](for demo)
// ES6
export default class MyClass extends Component {
}
// ES5
"use strict";
exports.__esModule = true;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var MyClass = (function (_Component) {
_inherits(MyClass, _Component);
function MyClass() {
_classCallCheck(this, MyClass);
_Component.apply(this, arguments);
}
return MyClass;
})(Component);
exports["default"] = MyClass;
module.exports = exports["default"];
Babel 6 with presets": ["es2015"]
enabled, see repo to reproduce this
// ES6
export default class MyClass extends Component {
}
// ES5
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var MyClass = function (_Component) {
_inherits(MyClass, _Component);
function MyClass() {
_classCallCheck(this, MyClass);
return _possibleConstructorReturn(this, Object.getPrototypeOf(MyClass).apply(this, arguments));
}
return MyClass;
}(Component);
exports.default = MyClass;
- http://www.2ality.com/2014/09/es6-modules-final.html
- http://www.2ality.com/2015/12/babel-commonjs.html
- http://stackoverflow.com/questions/33505992/babel-6-changes-how-it-exports-default
- http://www.jbrantly.com/es6-modules-with-typescript-and-webpack/
- http://www.sitepoint.com/transpiling-es6-modules-to-amd-commonjs-using-babel-gulp/
- https://medium.com/@kentcdodds/misunderstanding-es6-modules-upgrading-babel-tears-and-a-solution-ad2d5ab93ce0#.2q4yeggc9
- microsoft/TypeScript#5458
- facebook/react-native#4784