Skip to content

Commit 6a1d942

Browse files
committed
Replace clean-webpack-plugin with built-in CleanPlugin.
1 parent df84194 commit 6a1d942

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# bedrock-webpack ChangeLog
22

3+
## 11.4.0 - 2025-09-dd
4+
5+
### Changed
6+
- Replace `clean-webpack-plugin` with webpack 5.20+ built-in `CleanPlugin`.
7+
38
## 11.3.0 - 2025-08-25
49

510
### Changed

lib/index.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import webpack from 'webpack';
2626
import {merge as webpackMerge} from 'webpack-merge';
2727

2828
// webpack plugins
29-
import {CleanWebpackPlugin} from 'clean-webpack-plugin';
3029
import HtmlWebpackPlugin from 'html-webpack-plugin';
3130
import StatsPlugin from 'stats-webpack-plugin';
3231
import TerserPlugin from 'terser-webpack-plugin';
@@ -256,12 +255,18 @@ export async function bundle(options = {}) {
256255
webpackDefinePlugin.push(new webpack.DefinePlugin(defines));
257256

258257
// clean mode
259-
const webpackCleanPlugin = [];
258+
const webpackCleanOptions = {};
260259
if(command.webpackClean === 'true') {
261-
const opts = {
262-
verbose: command.webpackCleanVerbose === 'true'
263-
};
264-
webpackCleanPlugin.push(new CleanWebpackPlugin(opts));
260+
if(command.webpackCleanVerbose === 'true') {
261+
webpackCleanOptions.clean = {
262+
keep(asset) {
263+
console.warn(`clean-webpack-plugin: removed ${asset}`);
264+
return false;
265+
}
266+
};
267+
} else {
268+
webpackCleanOptions.clean = true;
269+
}
265270
}
266271

267272
// html webpack plugin
@@ -291,7 +296,8 @@ export async function bundle(options = {}) {
291296
output: {
292297
path: path.join(paths.local, 'js'),
293298
publicPath: path.join(paths.public, 'js/'),
294-
filename: '[name].[hash].js'
299+
filename: '[name].[hash].js',
300+
...webpackCleanOptions
295301
},
296302
resolve: {
297303
alias: {
@@ -417,7 +423,6 @@ export async function bundle(options = {}) {
417423
plugins: [
418424
...webpackHtmlPlugin,
419425
...webpackDefinePlugin,
420-
...webpackCleanPlugin,
421426
new VueLoaderPlugin(),
422427
...webpackProgressPlugin,
423428
...webpackHmrPlugin

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"@babel/preset-env": "^7.28.0",
3131
"app-root-path": "^3.0.0",
3232
"babel-loader": "^10.0.0",
33-
"clean-webpack-plugin": "^4.0.0",
3433
"core-js": "^3.45.1",
3534
"css-loader": "^7.1.2",
3635
"file-loader": "^6.2.0",

0 commit comments

Comments
 (0)