我正在尝试使用 Webpack + Babel 在 IE >= 11 中运行具有 ES2015 功能的 React 应用程序。设置是自定义的,使用inferno-compat
层,所以create-react-app
这里没有使用。
但是 - 尽管对我的和 webpack 配置应用了最新babel-polyfill
和babel-preset-env
实践,当我尝试使用 IE11 访问应用程序时.babelrc
,我的bundle.js 中仍然出现SCRIPT1002: Syntax 错误。
当我按照 IE 控制台中的语法错误参考进行操作时,这是生成的 bundle.js 中存在冲突的部分(特别是箭头函数):
function add(x, y) {
if (y === undefined) {
return yHolder => add(x, yHolder);
}
return x + y;
}
这些是 my 中的相关依赖项package.json
:
"dependencies": {
"inferno-redux": "^3.10.1",
"react": "^15.6.0",
"react-dom": "^15.6.0",
"react-ga": "^2.2.0",
"react-swipeable": "^4.1.0",
"redux": "^3.7.2",
"redux-saga": "^0.16.0",
"regenerator-runtime": "^0.11.0"
},
"devDependencies": {
//... stuff
"babel-cli": "^6.26.0",
"babel-core": "^6.25.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.1.1",
"babel-plugin-inferno": "^3.2.0",
"babel-plugin-module-resolver": "^2.7.1",
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
"babel-plugin-transform-es2015-spread": "^6.22.0",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-flow": "^6.23.0",
"babel-preset-react": "^6.24.1",
//... some more stuff
"webpack": "^3.8.1",
"webpack-bundle-analyzer": "^2.9.1",
"webpack-dev-middleware": "^1.12.2",
"webpack-dev-server": "^2.9.5",
"webpack-manifest-plugin": "^1.3.2",
"webpack-merge": "^4.1.1",
}
这是我的.babelrc
:
{
"presets":
[
"react",
"flow",
"es2015",
[
"env", {
"modules": "commonjs",
"targets": {
"browsers": ["last 2 versions", "ie >= 11"]
}
}
]
]
}
我包括babel-polyfill
在我的webpack.base.config.js
这里:
// ... stuff
entry: {
index: ['babel-polyfill', './index.js'],
},
// ... more stuff
有什么想法让它在 IE11 中运行吗?