今天对照着中文文档使用clean-webpack-plugin发现报错
TypeError: CleanWebpackPlugin is not a constructor
点开它里面的链接之后才发现原来是用法改了,好坑…
现在用法如下:
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const webpackConfig = {
plugins: [
/**
* All files inside webpack's output.path directory will be removed once, but the
* directory itself will not be. If using webpack 4+'s default configuration,
* everything under <PROJECT_DIR>/dist/ will be removed.
* Use cleanOnceBeforeBuildPatterns to override this behavior.
*
* During rebuilds, all webpack assets that are not used anymore
* will be removed automatically.
*
* See `Options and Defaults` for information
*/
new CleanWebpackPlugin(),
],
};
module.exports = webpackConfig;
里面的一些参数如下:
new CleanWebpackPlugin({
// Simulate the removal of files
//
// default: false
dry: true,
// Write Logs to Console
// (Always enabled when dry is true)
//
// default: false
verbose: true,
// Automatically remove all unused webpack assets on rebuild
//
// default: true
cleanStaleWebpackAssets: false,
// Do not allow removal of current webpack assets
//
// default: true
protectWebpackAssets: false,
// **WARNING**
//
// Notes for the below options:
//
// They are unsafe...so test initially with dry: true.
//
// Relative to webpack's output.path directory.
// If outside of webpack's output.path directory,
// use full path. path.join(process.cwd(), 'build/**/*')
//
// These options extend del's pattern matching API.
// See https://github.com/sindresorhus/del#patterns
// for pattern matching documentation
// Removes files once prior to Webpack compilation
// Not included in rebuilds (watch mode)
//
// Use !negative patterns to exclude files
//
// default: ['**/*']
cleanOnceBeforeBuildPatterns: ['**/*', '!static-files*'],
cleanOnceBeforeBuildPatterns: [], // disables cleanOnceBeforeBuildPatterns
// Removes files after every build (including watch mode) that match this pattern.
// Used for files that are not created directly by Webpack.
//
// Use !negative patterns to exclude files
//
// default: []
cleanAfterEveryBuildPatterns: ['static*.*', '!static1.js'],
// Allow clean patterns outside of process.cwd()
//
// requires dry option to be explicitly set
//
// default: false
dangerouslyAllowCleanPatternsOutsideProject: true,
});
浏览器渣翻,有需要的可以了解下
新的CleanWebpackPlugin ({
// 模拟文件的删除
//
// 默认值:false
干:是的,
// 将日志写入控制台
// (干燥时始终启用)
//
// 默认值:false
详细说明:是的,
// 在重建时自动删除所有未使用的webpack资产
//
// 默认值:true
cleanStaleWebpackAssets :false ,
// 不允许删除当前的webpack资产
//
// 默认值:true
protectWebpackAssets :false ,
// **警告**
//
// 以下选项的注释:
//
// 它们不安全......所以最初用干测试:真的。
//
// 相对于webpack的output.path目录。
// 如果在webpack的output.path目录之外,
// 使用完整路径 path.join(process.cwd(),'build / ** / *')
//
// 这些选项扩展了del的模式匹配API。
// 请参阅 https://github.com/sindresorhus/del#patterns
// 用于模式匹配文档
// 在Webpack编译之前删除一次文件
// 不包括在重建中(监视模式)
//
// 使用!负面模式排除文件
//
// 默认:['** / *']
cleanOnceBeforeBuildPatterns :[ ' ** / * ','!static-files * ' ] ,
cleanOnceBeforeBuildPatterns :[ ] ,// 禁用cleanOnceBeforeBuildPatterns
// 在每个与此模式匹配的构建(包括监视模式)后删除文件。
// 用于不是由Webpack直接创建的文件。
//
// 使用!负面模式排除文件
//
// 默认:[]
cleanAfterEveryBuildPatterns :[ ' static *。* ','!static1.js ' ] ,
// 在process.cwd()之外允许干净的模式
//
// 需要明确设置干选项
//
// 默认值:false
dangerouslyAllowCleanPatternsOutsideProject :true ,
} );