我有一个Nx单体库(https://nx.dev)。
它有一个包含Nx缓存的文件夹(./node_modules/.cache/nx/
)。
目前其大小超过了3GB。
是否有清理该缓存的命令?
我有一个Nx单体库(https://nx.dev)。
它有一个包含Nx缓存的文件夹(./node_modules/.cache/nx/
)。
目前其大小超过了3GB。
是否有清理该缓存的命令?
nx reset
可以清除缓存。
nx reset
的文档: https://nx.dev/nx/reset#reset
有关缓存的文档在此处:https://nx.dev/using-nx/caching#local-computation-caching
上面提到的nx clear-cache
是针对jest缓存的。虽然我想评论,但没有声望 :)
只需删除整个“nx”缓存文件夹:
rm -rf ./node_modules/.cache/nx
nx help
命令会输出以下内容:nx reset - 清除所有缓存的 Nx 构件 (...) [别名: clear-cache]
。但是在 CLI 文档中并没有找到 reset
命令的相关说明。 - isnot2bad "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);
}
});
}