вот мой код, я трачу много времени на решение этой проблемы, но не могу ее решить , Мне нужна помощь. Я нашел много способов ее решения, и я обнаружил, что существует множество ситуаций, которые могут вызвать эту проблему. Моя версия webpack - «^ 4.44.1», моя версия webpack-cli - «^ 3.3.12»
// webpack.common.js
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const autoprefixer = require("autoprefixer");
const os = require("os");
const HappyPack = require("happypack");
const webpack = require("webpack");
const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
const srcDir = path.join(__dirname, "../src");
const devMode = process.env.NODE_ENV !== "production";
module.exports = {
entry: {
main: path.join(__dirname, "../src/index.js"),
},
output: {
path: path.join(__dirname, "../dist"),
filename: "[name].[chunk:8].js",
chunkFilename: "chunk/[name].[chunkhash:8].js",
},
model: {
rules: [
{
test: /\.less$/,
use: [
devMode ? "style-loader" : MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader",
"less-loader",
],
},
{
test: /\.css$/,
use: [
devMode ? "style-loader" : MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader",
],
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
use: ["url-loader"],
include: [srcDir],
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
use: ["url-loader"],
include: [srcDir],
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
use: ["url-loader"],
include: [srcDir],
},
{
test: /\.(js|jsx)$/,
include: [srcDir],
exclude: /(node_modules|bower_components)/,
use: ["babel-loader?cacheDirectory=true"],
},
],
},
// 插件
plugins: [
new webpack.LoaderOptionsPlugin({
options: {
context: __dirname,
postcss: [autoprefixer],
},
}),
new HtmlWebpackPlugin({
template: `${srcDir}/index.html`,
}),
new MiniCssExtractPlugin({
filename: "[name].[contenthash:8].css",
chunkFilename: "chunk/[id].[contenthash:8].css",
}),
//开启 happypack 的线程池
new HappyPack({
id: "happybabel",
loaders: ["babel-loader?cacheDirectory=true"],
threadPool: happyThreadPool,
verbose: true,
}),
],
resolve: {
alias: {
"@": srcDir,
"@pages": `${srcDir}/pages`,
},
},
};
const webpack = require("webpack");
const { merge } = require("webpack-merge");
const commonConfig = require("./webpack.common.js");
// const
module.exports = merge(commonConfig, {
mode: "development",
// 开发环境本地启动的服务配置
devServer: {
port: 9000,
hot: true,
open: true,
// historyApiFallback: true,
compress: true,
// 接口代理转发
proxy: {
"/testapi": {
target: "",
// changeOrigin: true,
// secure: false,
pathRewrite: { "^/testapi": "" },
},
},
},
// plugins: [
// // new webpack.NamedModulesPlugin(),
// // new webpack.HotModuleReplacementPlugin(),
// ],
});
// webpack.dev. js // мой документ
Я обнаружил, что должен использовать LoaderOptionsPlugin, но не могу добавить плагин с помощью npm или пряжа