From 78d4efd8f361e3f29fff3886a663be7ece79d286 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sun, 30 May 2021 14:33:42 +0200 Subject: [PATCH] clean dist folder when compiling --- web/webpack.config.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/web/webpack.config.js b/web/webpack.config.js index 6a765e081..9945397a1 100644 --- a/web/webpack.config.js +++ b/web/webpack.config.js @@ -20,11 +20,12 @@ const isProduction = process.env.NODE_ENV === 'production'; const hasSentryToken = process.env.SENTRY_AUTH_TOKEN !== undefined; const jsBundleId = getJsBundleId(); -// copy static files to dist file +// copy static files to dist folder const copyWebpackCommands = [ { from: `${STATIC_ROOT}/index-web.html`, to: `${DIST_ROOT}/index.html`, + // add javascript script to index.html, generate/insert metatags transform(content, path) { return insertToHead(content.toString(), buildBasicOgMetadata()); }, @@ -80,6 +81,12 @@ if (fs.existsSync(ROBOTS_TXT_PATH)) { }); } +// clear the dist folder of existing js files before compilation +let regex = /^.*\.(json|js|map)$/; +fs.readdirSync(`${DIST_ROOT}/public/`) + .filter(f => regex.test(f)) + .map(f => fs.unlinkSync(`${DIST_ROOT}/public/` + f)); + let plugins = [ new WriteFilePlugin(), new CopyWebpackPlugin(copyWebpackCommands),