Pax*_*ach 5 javascript nomachine-nx nrwl nrwl-nx nx.dev
我使用 Nx monorepo ( https://nx.dev )。它有一个包含 Nx 缓存的文件夹 (./node_moules/.cache/nx/)。它现在的大小超过 3GB。
是否有不时清除此缓存的命令?
Cob*_*ear 96
nx reset清除缓存。
文档:https nx reset: //nx.dev/nx/reset#reset
有关缓存的文档:https ://nx.dev/using-nx/caching#local-computation-caching
上面的答案nx clear-cache是针对 jest 缓存的。我会发表评论,但没有代表:)
meg*_*lop 77
只需删除整个“nx”缓存文件夹:
rm -rf ./node_modules/.cache/nx
Run Code Online (Sandbox Code Playgroud)
Joe*_*ung 35
这适用于今天(2022 年 2 月 12 日)的最新版本。我不确定为什么它不再出现在 CLI 文档中,尽管有证据表明它过去就存在: https: //nx.dev/cli/clear-cache
nx clear-cache
我已经实现了这样的解决方案,但觉得不方便。也许NX有一个清除其缓存的命令,但我没有找到它。
包.json
"scripts": {
"nx": "nx",
"postnx": "node checkAndClearCache.js",
...
Run Code Online (Sandbox Code Playgroud)
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);
}
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2396 次 |
| 最近记录: |