我想处理我的jsx代码,所以我写这样的webpakc.config.js:
{
test: /\.js$/,
loaders: ['react-hot', 'babel-loader?presets[]=es2015'],
exclude: /node_modules/
}
但它没有处理我的jsx代码并抛出这样的错误: The error threw in terminal
通过Google我发现我需要将presets['react']
添加到我的配置文件中。所以我像这样更新配置:
{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
query: {
presets: ['react', 'es2015']
},
exclude: /node_modules/
}
但它又引发了一个错误: A new error threw after update config file
我是webpack的新手,我该怎么办?
答案 0 :(得分:13)
第一个错误似乎是JSX中的语法错误。很难从评论中分辨出它是什么。尝试发布JSX文件内容。
关于第二个错误: 不需要将特定加载器的查询参数指定为JSON对象。您也可以将它们指定为与加载程序名称相邻的查询字符串。例如。相同的配置可以用这一行表示:
loaders: ['react-hot', 'babel?presets[]=react,presets[]=es2015']
当然,一旦使用上述内容,您将需要删除查询JSON。 更多信息:https://webpack.github.io/docs/using-loaders.html#query-parameters