【发布时间】:2020-01-03 14:30:11
【问题描述】:
无法使用 react 配置 webpack
以下是错误:
配置对象无效。 Webpack 已使用与 API 模式不匹配的配置对象进行初始化。 - configuration.entry['main'] 不应包含项目 '-' 两次。 -> 非空字符串的非空数组
我已经配置了webpack并尝试了
下面是 webpack.config.js
const path = require('path');
const HWP = require('html-webpack-plugin');
module.exports = {
entry: path.join(__dirname, '/src/index.js'),
output: {
filename: 'build.js',
path: path.join(__dirname, '/dist')},
module:{
rules:[{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}]
},
plugins:[
new HWP(
{template: path.join(__dirname,'/src/index.html')}
)
]
}
【问题讨论】:
-
只需使用 create-react-app 即可避免自己配置 webpack。
-
我知道 create-react-app。我正在尝试了解有关 webpack 的更多信息。
-
哪一行代码出错了?
-
我认为 entry 需要是一个数组或对象。试试
entry: { main: path.join(__dirname, '/src/index.js') }, -
onfiguration.entry['main'] 不应包含两次“—”项。