我想处理我的 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 的新手,我该怎么办?
请您参考如下方法:
第一个错误似乎是 JSX 中的语法错误。从评论中很难看出它是什么。尝试发布 JSX 文件内容。
关于第二个错误: 特定加载器的查询参数不必指定为 JSON 对象。您也可以将它们指定为与加载程序名称相邻的查询字符串。例如。可以用这一行表达相同的配置:
loaders: ['react-hot', 'babel?presets[]=react,presets[]=es2015']
当然,使用上述内容后,您需要删除查询 JSON。 更多信息请点击:https://webpack.github.io/docs/using-loaders.html#query-parameters






