錯誤原因
這是由于clean-webpack-plugin
版本問題導(dǎo)致的,在2.0.0以上的版本中,對clean-webpack-plugin
的使用有了一定的變化
具體使用
- 在2.0.0版本以前,也就是1.x版本中,官方文檔指示的配置是這樣的
plugins: [
new CleanWebpackPlugin(paths [, {options}])
]
也就是大多數(shù)視頻中提到的傳入一個數(shù)組,指定要刪除的目錄,但在我們跟著做的過程中就會報標(biāo)題中的那個錯誤
- 在2.x版本以后,官方對它的使用進(jìn)行了修改
plugins: [
// See Options and Defaults
new CleanWebpackPlugin()
],
- 可以看到去掉了復(fù)雜的參數(shù),直接new即可使用
- 當(dāng)然里面仍然可以配置,但是只能傳入一個對象配置,無法再在第一個參數(shù)傳入數(shù)組指定刪除目錄
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: disabled
cleanAfterEveryBuildPatterns: ['static*.*', '!static1.js'],
// Allow clean patterns outside of process.cwd()
//
// requires dry option to be explicitly set
//
// default: false
dangerouslyAllowCleanPatternsOutsideProject: true,
dry: true,
});