@@ -28,7 +28,6 @@ const deleteUnusedEntriesPluginUtil = require('./plugins/delete-unused-entries')
28
28
const entryFilesManifestPlugin = require ( './plugins/entry-files-manifest' ) ;
29
29
const manifestPluginUtil = require ( './plugins/manifest' ) ;
30
30
const variableProviderPluginUtil = require ( './plugins/variable-provider' ) ;
31
- const cleanPluginUtil = require ( './plugins/clean' ) ;
32
31
const definePluginUtil = require ( './plugins/define' ) ;
33
32
const terserPluginUtil = require ( './plugins/terser' ) ;
34
33
const optimizeCssAssetsUtil = require ( './plugins/optimize-css-assets' ) ;
@@ -40,6 +39,7 @@ const PluginPriorities = require('./plugins/plugin-priorities');
40
39
const applyOptionsCallback = require ( './utils/apply-options-callback' ) ;
41
40
const copyEntryTmpName = require ( './utils/copyEntryTmpName' ) ;
42
41
const getVueVersion = require ( './utils/get-vue-version' ) ;
42
+ const multimatch = require ( 'multimatch' ) ;
43
43
const tmp = require ( 'tmp' ) ;
44
44
const fs = require ( 'fs' ) ;
45
45
const path = require ( 'path' ) ;
@@ -244,6 +244,7 @@ class ConfigGenerator {
244
244
}
245
245
246
246
return {
247
+ clean : this . buildCleanConfig ( ) ,
247
248
path : this . webpackConfig . outputPath ,
248
249
filename : filename ,
249
250
// default "asset module" filename
@@ -256,6 +257,26 @@ class ConfigGenerator {
256
257
} ;
257
258
}
258
259
260
+ /**
261
+ * @returns {import('webpack').CleanOptions|boolean }
262
+ */
263
+ buildCleanConfig ( ) {
264
+ if ( ! this . webpackConfig . cleanupOutput ) {
265
+ return false ;
266
+ }
267
+
268
+ const cleanedPaths = [ ] . concat ( this . webpackConfig . cleanWebpackPluginPaths ) ;
269
+ // works around a bug where manifest.json is emitted when
270
+ // using dev-server... but then CleanWebpackPlugin deletes it
271
+ cleanedPaths . push ( '!manifest.json' ) ;
272
+
273
+ const cleanConfig = {
274
+ keep : ( path ) => multimatch ( path , cleanedPaths ) . length === 0
275
+ } ;
276
+
277
+ return applyOptionsCallback ( this . webpackConfig . cleanWebpackPluginOptionsCallback , cleanConfig ) ;
278
+ }
279
+
259
280
buildRulesConfig ( ) {
260
281
const applyRuleConfigurationCallback = ( name , defaultRules ) => {
261
282
return applyOptionsCallback ( this . webpackConfig . loaderConfigurationCallbacks [ name ] , defaultRules ) ;
@@ -457,8 +478,6 @@ class ConfigGenerator {
457
478
458
479
variableProviderPluginUtil ( plugins , this . webpackConfig ) ;
459
480
460
- cleanPluginUtil ( plugins , this . webpackConfig ) ;
461
-
462
481
definePluginUtil ( plugins , this . webpackConfig ) ;
463
482
464
483
notifierPluginUtil ( plugins , this . webpackConfig ) ;
0 commit comments