当我运行我的反应应用程序的构建时,我得到了:ERROR in bundle.js from UglifyJs
Unexpected token: name
我找到了这个https://github.com/joeeames/WebpackFundamentalsCourse/issues/3
他们建议使用babel-reset-es2015,但我需要babel-preset-react。
我的webpack配置:
const path = require('path')
const ExtractTextPlugin = require("extract-text-webpack-plugin")
const extractSass = new ExtractTextPlugin({
filename: "style.css",
disable: process.env.NODE_ENV === "development"
});
const config = {
entry: "./src/index.js",
output: {
filename: "bundle.js",
path: path.resolve(__dirname + "/dist")
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
query: {presets:['react']}
},
{
test: /\.js$/,
enforce: 'pre',
loader: 'eslint-loader',
options: {
emitWarning: true,
}
},
{ test: /\.html$/,
use:[{
loader: 'html-loader',
options: {
minimize:true
}
}]
},
{
test: /\.scss$/,
use: extractSass.extract({
use: [{
loader: "css-loader"
}, {
loader: "sass-loader"
}],
fallback: "style-loader"
})
}
]},
plugins: [
extractSass
],
node:{
fs: "empty"
}
}
module.exports = config
答案 0 :(得分:0)
你可以拥有两者,它们不是互斥的。此外,query
已替换为网络包2中的options
,就像您已经在其他加载程序中使用它一样。出于兼容性原因,query
仍然存在,但您应该只使用options
。
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
options: {
presets: ['es2015', 'react']
}
},