clear stale js files on nonprod environments

This commit is contained in:
Anthony 2021-07-07 17:20:37 +02:00 committed by jessopb
parent a422e857e3
commit 0ef61fc575

View file

@ -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({