我已经尝试了 2 种方法同时对我的 *.js 文件使用 ng-annotate 和 babel 加载器。
{ //this worked
test: /.js?$/,
loader: 'ng-annotate!babel?presets[]=es2015'
}
{ // this broke down
test: /.js?$/,
loader: 'ng-annotate!babel-loader',
query: {
presets: ['es2015']
}
}
为什么第二个加载器配置不起作用?有什么想法吗?
经过一番挖掘,我发现这是解决方案:
{
test: /.js$/,
exclude: /(node_modules|bower_components)/,
loaders: ['ng-annotate', 'babel?presets[]=es2015']
},
我相信这与 webpack 如何加载查询/预设有关。它不知道预设适用于哪个加载程序。
请参阅 babel-loader 选项,它显示了如何将选项作为查询字符串传递