网页套件5、清除Css、清除网页套件插件、
大家好,我创建了一个项目,使用Webpack 5来处理Scss =〉CSS转换以及更多内容。
我已经把所有的东西都修好了除了PurgeCss
当我运行Webpack时,我一直收到错误PurgeCss不是构造函数。
有趣的是,这曾经是工作,但自从我更新了package.json文件,以摆脱漏洞,现在它崩溃。
The full code can be found on the GitHub repo.。
如果有人能告诉我为什么,我将不胜感激,谢谢。
const path = require("path");
// const glob = require("glob");
const _MiniCssExtractPlugin = require("mini-css-extract-plugin");
const _StyleLintPlugin = require("stylelint-webpack-plugin");
const _ESLintPlugin = require("eslint-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const _CopyPlugin = require("copy-webpack-plugin");
// const { _PurgeCSSPlugin } = require("purgecss-webpack-plugin");
// const PATHS = {
// src: path.join(__dirname, "../src"),
// };
// const PurgecssPlugin = new _PurgeCSSPlugin({
// paths: glob.sync(`${PATHS.src}/**/*`),
// });
const MiniCssExtractPlugin = new _MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css",
});
const ESLintPlugin = new _ESLintPlugin({
overrideConfigFile: path.resolve(__dirname, ".eslintrc"),
context: path.resolve(__dirname, "../src/js"),
files: "**/*.js",
});
const StyleLintPlugin = new _StyleLintPlugin({
configFile: path.resolve(__dirname, "stylelint.config.js"),
//configBasedir: path.resolve(__dirname, "./node_modules/"),
context: path.resolve(__dirname, "../src/scss"),
files: "**/*.scss",
syntax: "scss",
});
/**
* If getting an error during npm start or watch it's
* most posable because the src/fonts or src/img folders are empty
*/
const CopyPlugin = new _CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, "../src/img/"),
to: path.resolve(__dirname, "../../project/public/img/"),
},
{
from: path.resolve(__dirname, "../src/fonts/"),
to: path.resolve(__dirname, "../../project/public/fonts/"),
},
{
from: path.resolve(__dirname, "../src/index.php"),
to: path.resolve(__dirname, "../../project/public/index.php"),
},
],
});
module.exports = {
CleanWebpackPlugin: new CleanWebpackPlugin(),
MiniCssExtractPlugin: MiniCssExtractPlugin,
// PurgecssPlugin: PurgecssPlugin,
ESLintPlugin: ESLintPlugin,
StyleLintPlugin: StyleLintPlugin,
CopyPlugin: CopyPlugin,
};
1条答案
按热度按时间von4xj4u1#
所以很明显这是一个webpack-purgecss-plugin 5.0的问题,因为webpack5.0所以我降级插件到4.1.3,它再次工作。