Webpack “网页给我错误”;无效的配置对象';插件'&引用;
我的网页包认为“插件”是无效的对象,我不明白为什么 以下是屏幕截图中的错误: 无效的配置对象。已使用与API架构不匹配的配置对象初始化Web包。 -configuration.module具有未知属性“plugins”。 这是我的webpack.prod.js配置文件Webpack “网页给我错误”;无效的配置对象';插件'&引用;,webpack,Webpack,我的网页包认为“插件”是无效的对象,我不明白为什么 以下是屏幕截图中的错误: 无效的配置对象。已使用与API架构不匹配的配置对象初始化Web包。 -configuration.module具有未知属性“plugins”。 这是我的webpack.prod.js配置文件 const path = require('path') const webpack = require('webpack') const HtmlWebPackPlugin = require("html-webpack-pl
const path = require('path')
const webpack = require('webpack')
const HtmlWebPackPlugin = require("html-webpack-plugin")
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const WorkboxPlugin = require('workbox-webpack-plugin')
module.exports = {
entry: "./src/js/index.js",
mode: 'production',
output: {
libraryTarget: 'var',
library: 'Client'
},
module: {
rules: [
{
test: '/\.js$/',
exclude: /node_modules/,
loader: "babel-loader"
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000',
use: [ MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader' ]
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/'
}
}
]
}
],
plugins: [
new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html",
}),
new MiniCssExtractPlugin({filename: '[name].css'}),
new WorkboxPlugin.GenerateSW()
]
}
}
配置文件有一个错误:“plugins”对象不应该是“module”的子对象,但需要更高一级。(见网页文档:) 尝试:
const path = require('path')
const webpack = require('webpack')
const HtmlWebPackPlugin = require("html-webpack-plugin")
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const WorkboxPlugin = require('workbox-webpack-plugin')
module.exports = {
entry: "./src/js/index.js",
mode: 'production',
output: {
libraryTarget: 'var',
library: 'Client'
},
module: {
rules: [
{
test: '/\.js$/',
exclude: /node_modules/,
loader: "babel-loader"
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000',
use: [ MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader' ]
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/'
}
}]
}
],
},
plugins: [
new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html",
}),
new MiniCssExtractPlugin({filename: '[name].css'}),
new WorkboxPlugin.GenerateSW()
]
}