From 0ef61fc5756eafd388691f0eb3f7c4b8a7131b6c Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 7 Jul 2021 17:20:37 +0200 Subject: [PATCH] clear stale js files on nonprod environments --- web/webpack.config.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/web/webpack.config.js b/web/webpack.config.js index 436c919b4..96883981b 100644 --- a/web/webpack.config.js +++ b/web/webpack.config.js @@ -77,6 +77,15 @@ if (fs.existsSync(CUSTOM_OG_PATH)) { }); } +// clear the dist folder of existing js files before compilation +let regex = /^.*\.(json|js|map)$/; +// only run on nonprod environments to avoid side effects on prod +if (!isProduction) { + fs.readdirSync(`${DIST_ROOT}/public/`) + .filter(f => regex.test(f)) + .map(f => fs.unlinkSync(`${DIST_ROOT}/public/` + f)); +} + const ROBOTS_TXT_PATH = `${CUSTOM_ROOT}/robots.txt`; if (fs.existsSync(ROBOTS_TXT_PATH)) { copyWebpackCommands.push({