remove only chunks older then 2 days, to allow UI to still load them and not require a reload / F5

This commit is contained in:
Ralf Becker 2021-09-26 10:53:27 +02:00
parent 281e71ef71
commit 5c19e0c699

View File

@ -11,14 +11,21 @@
import path from 'path'; import path from 'path';
import babel from '@babel/core'; import babel from '@babel/core';
import { readFileSync, readdirSync, statSync } from "fs"; import { readFileSync, readdirSync, statSync, unlinkSync } from "fs";
import rimraf from 'rimraf'; //import rimraf from 'rimraf';
import { minify } from 'terser'; import { minify } from 'terser';
import resolve from '@rollup/plugin-node-resolve'; import resolve from '@rollup/plugin-node-resolve';
// Best practice: use this // Best practice: use this
//rimraf.sync('./dist/'); //rimraf.sync('./dist/');
rimraf.sync('./chunks/'); //rimraf.sync('./chunks/');
// remove only chunks older then 2 days, to allow UI to still load them and not require a reload / F5
const rm_older = Date.now() - 48*3600000;
readdirSync('./chunks').forEach(name => {
const stat = statSync('./chunks/'+name);
if (stat.atimeMs < rm_older) unlinkSync('./chunks/'+name);
});
// Turn on minification // Turn on minification
const do_minify = true; const do_minify = true;