简体   繁体   English

使用 webpack 配置创建 React 应用程序时出现无效配置错误

[英]Invalid configuration error while creating a react app with webpack configuration

Unable to configure webpack with react无法使用 react 配置 webpack

below is error :下面是错误:

Invalid configuration object.无效的配置对象。 Webpack has been initialised using a configuration object that does not match the API schema. Webpack 已使用与 API 架构不匹配的配置对象进行初始化。 - configuration.entry['main'] should not contain the item '—' twice. - configuration.entry['main'] 不应包含项目 '—' 两次。 -> A non-empty array of non-empty strings -> 非空字符串的非空数组

I have configured webpack and tried我已经配置了 webpack 并尝试过

below is webpack.config.js下面是 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')}
   )
  ]
}

在此处输入图片说明

在此处输入图片说明

i think this will work 我认为这会工作

 const path = require('path');
 const HWP = require('html-webpack-plugin');
 module.exports = {
   entry: ['./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')}
   )
  ]
}

如下更改package.json中的脚本启动命令使其生效,

"start": "webpack-dev-server --config webpack.config.js --port 3000",

I solve this adding "--live-reload false" to my start command.我解决了在启动命令中添加“--live-reload false”的问题。

"scripts": { “脚本”:{

 "ng": "ng", "start": "ng serve --live-reload false", "build": "ng build", "watch": "ng build --watch --configuration development", "test": "ng test", "build:single-spa:mf-test2": "ng build mf-test2 --prod", "serve:single-spa:mf-test2": "ng s --project mf-test2 --disable-host-check --port NaN --live-reload false" },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM