wds:无效的配置对象。已使用与API模式不匹配的配置对象初始化了Webpack

时间:2019-03-13 09:45:30

标签: api webpack schema html-webpack-plugin

问题!!!获取此错误消息,API模式存在问题。 html-webpack-plugin问题。如果我删除html-webpack-plugin一切正常,则没有错误消息。如何使其与html-webpack-plugin一起使用?

谢谢!

问题!!!获取此错误消息,API模式存在问题。 html-webpack-plugin问题。如果我删除html-webpack-plugin一切正常,则没有错误消息。如何使其与html-webpack-plugin一起使用?

谢谢!

webpack.config.js

const path = require('path'); 
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

const isProduction = process.env.NODE_ENV === 'production';

const config = {
    entry: ['@babel/polyfill', './src/index.js'],
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'js/bundle.js',
    },
    devServer: {
        contentBase: './dist'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader'
                }
            },
            { 
                test: /\.(le|c)ss$/, // .less and .css
                use: [ 
                    isProduction ? MiniCssExtractPlugin.loader : 'style-loader', 
                    'css-loader', 
                    'less-loader'
                ],
            },
        ]
    },
    plugins: [
        new HtmlWebpackPlugin(),
        isProduction ? [new MiniCssExtractPlugin()] : []
    ],
    devtool: 'source-map',
};

module.exports = config;

package.json

"main": "index.js",
  "scripts": {
    "dev": "webpack --mode development",
    "production": "NODE_ENV=production webpack --mode=production",
    "start": "webpack-dev-server --mode development --open"
  },
  "keywords": [],
  "author": "OS",
  "license": "MIT",
  "devDependencies": {
    "@babel/core": "^7.3.4",
    "@babel/preset-env": "^7.3.4",
    "babel-loader": "^8.0.5",
    "css-loader": "^2.1.1",
    "html-webpack-plugin": "^3.2.0",
    "less": "^3.9.0",
    "less-loader": "^4.1.0",
    "mini-css-extract-plugin": "^0.5.0",
    "node-sass": "^4.11.0",
    "sass-loader": "^7.1.0",
    "style-loader": "^0.23.1",
    "webpack": "^4.29.6",
    "webpack-cli": "^3.2.3",
    "webpack-dev-server": "^3.2.1"
  },
  "dependencies": {
    "@babel/polyfill": "^7.2.5"
  }
}

0 个答案:

没有答案