Babel 6.0.20模块功能在IE8中不起作用 [英] Babel 6.0.20 Modules feature not work in IE8
问题描述
我正在尝试在 header.js中导出es6模块
:
export default {
setHeaderHighlight: function (index) {
// do somethings
}
};
并将其导入 index.js
:
import header from "./header.js"
$(function () {
header.setHeaderHighlight(0);
});
然后转换出现在 index.bundle.js
:
var _header = __webpack_require__(129);
var _header2 = _interopRequireDefault(_header);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj }; // crash here
}
所以这就是问题,ie8会上升预期标识符
的异常{default:obj}
,但每件事都可以> = ie9。
So here is the problem, ie8 will rise a Expected identifier
Exception at { default: obj }
, but everythings is ok >=ie9.
我可以做些什么吗?
推荐答案
默认情况下,Babel 6.x需要你启用一组明确的转换。标准 es2015
预设将ES6转换为ES5,但IE8与ES5不兼容。在这种情况下,如果您查看插件列表,您将看到
By default, Babel 6.x requires you to enable an explicit set of transformations. The standard es2015
preset converts ES6 to ES5, however IE8 is not ES5-compatible. In this case, if you look at the plugins list, you will see
- transform-es3-member-expression-literals
- transform-es3-property-literals
这些会将您的属性转换为与IE8兼容。通常在Babel 6.x中,您可以将这些名称作为插件
数组的一部分传递给预设
数组并安装变换通过
These will convert your properties to be compatible with IE8. Generally in Babel 6.x you'd do this by passing those names as part of your plugins
array, alongside the presets
array and install the transforms via
npm install --save-dev babel-plugin-transform-es3-member-expression-literals babel-plugin-transform-es3-property-literals
这篇关于Babel 6.0.20模块功能在IE8中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!