webpack.config.js:
module.exports = {
entry: __dirname + '/src/app.js',
output: {
path: __dirname + '/dist',
filename: 'test.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['env', {
targets: {
chrome: 52
}
}]
}
}
}
]
}
};
Run Code Online (Sandbox Code Playgroud)
看起来很简单,但它会引发错误
模块构建失败:ReferenceError:[BABEL] /src/app.js:未知选项:foreign.targets.查看http://babeljs.io/docs/usage/options/了解有关选项的更多信息.
没有任何意义.错误由"env"预设的选项触发.任何关于为什么babel预设突然不接受选项的想法?
弄清楚了.带有选项的预设应该是嵌套数组,因此正确的选项列表应该是这样的:
options: {
presets: [
['env', {
targets: {
chrome: 52
}
}]
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1184 次 |
| 最近记录: |