我有一个 Nx monorepo ( https://nx.dev )。它有一个带有 Nx 缓存 ( ./node_modules/.cache/nx/
) 的文件夹。它现在的大小超过 3GB。
是否有清除此缓存的命令?
我有一个 Nx monorepo ( https://nx.dev )。它有一个带有 Nx 缓存 ( ./node_modules/.cache/nx/
) 的文件夹。它现在的大小超过 3GB。
是否有清除此缓存的命令?
只需删除整个“nx”缓存文件夹:
rm -rf ./node_modules/.cache/nx
这适用于今天(2022 年 2 月 12 日)的最新版本。我不确定为什么这不再出现在 CLI 文档中,尽管有证据表明它过去存在:https ://nx.dev/cli/clear-cache
nx clear-cache
我已经实现了这样的解决方案,但觉得不方便。也许NX有清除缓存的命令,但我没有找到。
包.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);
}
});
}
nx reset
清除缓存。此处的文档:https ://nx.dev/using-nx/caching#local-computation-caching
上面的答案nx clear-cache
是针对开玩笑的缓存。我会发表评论但没有代表:)