I'm trying to compile my React app with support for ES7 decorators as I'm using the autobind-decorator but webpack says there is an "Unexpected token" with the router, which is the entry file for the app. I've tried various versions of babel related npms, using the the "state-0" and "transform-runtime" and they all result in the same error. Anyone's help would be very much appreciated :)
答案 0 :(得分:2)
此错误的原因是webpack.config.js
文件中的加载程序配置不正确。您需要在加载程序配置中的presets
字段下提供query
:
loaders: [
{
test: /\.jsx?$/,
loader: 'babel',
query: {
presets: ['es2015', 'react', 'stage-1']
}
}
]
答案 1 :(得分:0)
根据the README of babel-loader,您应该在配置中使用query
字段,如下所示:
module: {
loaders: [
{
test: /\.jsx?$/,
include: // ....
loader: 'babel',
query: {
presets: [/*presets list*/],
plugins: [/*plugins list*/]
}
}
]
}