clean dist folder when compiling

This commit is contained in:
Anthony 2021-05-30 14:33:42 +02:00 committed by Jeremy Kauffman
parent 2e5cfe7a1e
commit 78d4efd8f3

View file

@ -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),