我从mini-css-extract-plugin的GitHub获得了基本配置,并且Hot Module Replacement无法正常工作。即使使用基本的HTML,CSS和JS。
我正在使用
"css-loader": "^2.1.1",
"mini-css-extract-plugin": "^0.6.0",
"webpack": "^4.30.0",
"webpack-cli": "^3.3.2"
我的脚本正在更改Webpack的模式
"scripts": {
"serve": "webpack --mode development --watch",
"dist": "webpack --mode production"
},
这是我的Webpack配置文件
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
}),
],
entry: ["./style.css", "./app.js"],
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: "../",
hmr: process.env.NODE_ENV === "development",
reloadAll: true,
},
},
"css-loader",
],
},
],
},
};