我可能会对babel-preset-env实际上做了什么感到困惑。我的假设是它会将我的代码转换为我的目标浏览器,包括任何必要的polyfill。虽然我的代码中似乎不是这种情况......
我的代码:
import "babel-polyfill"
...
var k = Object.values({ x: 's' });
我的宝贝设置:
"presets": [
[ "env", {
"useBuiltIns": true,
"targets": {
"browsers": ["last 2 versions", "IE 10"]
}
}]
]
转换后的代码仍然包含Object.values
,IE 10悄然死亡(它确实很简单 - 我可以看到代码的其余部分发生变化 - 似乎只是针对错误)。
Package.json(其中一些导入未使用):
"core-js": "^2.5.1",
"opentype.js": "^0.7.2",
"svg.draggable.js": "^2.2.1",
"svg.js": "^2.6.3",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.0",
"babel-preset-latest": "^6.24.1",
"babel-register": "^6.24.1",
"clean-webpack-plugin": "^0.1.16",
"compression-webpack-plugin": "^1.0.0",
"copy-webpack-plugin": "^4.0.1",
"imports-loader": "^0.7.1",
"mocha": "^3.5.0",
"webpack": "^3.4.1",
"webpack-dev-server": "^2.8.2",
"webpack-merge": "^4.1.0"
答案 0 :(得分:1)
babel-preset-env
仅处理转换语法,而不是填充标准库功能。
听起来你的配置中需要useBuiltins: true
。您还需要按照其他说明操作,安装core-js
并为babel-polyfill
添加导入。
或者,您只需加载babel-polyfill
本身,而不是完全依赖babel-preset-env
。