I have implemented such a solution, but do not find it convenient.
Perhaps NX has a command to clear its cache, but I did not find it.
package.json
"scripts": {
"nx": "nx",
"postnx": "node checkAndClearCache.js",
...
checkAndClearCache.js
const fs = require('fs');
const rimraf = require('rimraf');
const getSize = require('get-folder-size');
const cachePath = 'node_modules/.cache/nx';
const maxCacheMb = 2048;
if (fs.existsSync(cachePath)) {
getSize(cachePath, (err, size) => {
if (err) {
throw err;
}
const MBSize = (size / 1024 / 1024).toFixed(2);
console.log(`*** NX cache size is ${MBSize} Megabytes`);
if (MBSize > maxCacheMb) {
console.log('*** CLEAR NX CACHE ***');
rimraf.sync(cachePath);
}
});
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…