From c6f9e240d89fed91604a881868edaf3b836fcdee Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Tue, 14 Sep 2021 10:09:23 +0200 Subject: [PATCH] Reintroduce clean webpack plugin We used custom script because we were stuck with the old version the cleanup plugin and it had some issues. Now with webpack5 we can use the plugin again. [MAILPOET-3214] --- webpack.config.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 6fe95e5d1c..ea382c221b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,6 @@ const webpack = require('webpack'); const { WebpackManifestPlugin } = require('webpack-manifest-plugin'); +const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const webpackTerserPlugin = require('terser-webpack-plugin'); const webpackCopyPlugin = require('copy-webpack-plugin'); const path = require('path'); @@ -430,7 +431,7 @@ const postEditorBlock = { }, }; -module.exports = [adminConfig, publicConfig, migratorConfig, formPreviewConfig, testConfig, postEditorBlock].map((config) => { +module.exports = [publicConfig, adminConfig, migratorConfig, formPreviewConfig, testConfig, postEditorBlock].map((config, index) => { if (config.name !== 'test') { config.plugins = config.plugins || []; config.plugins.push( @@ -440,10 +441,9 @@ module.exports = [adminConfig, publicConfig, migratorConfig, formPreviewConfig, }) ); } - const finalConfig = Object.assign({}, baseConfig, config); - // Clean output paths before build - if (finalConfig.output && finalConfig.output.path) { - del.sync([path.resolve(finalConfig.output.path, '**/*')]); + // Cleanup output path but only once to keep output files for subsequent builds + if (index === 0) { + config.plugins.unshift(new CleanWebpackPlugin()); } - return finalConfig; + return Object.assign({}, baseConfig, config); });