admin管理员组文章数量:1134240
I have an Nx monorepo ().
It has a folder with Nx cache (./node_modules/.cache/nx/
).
Its size for now is over 3GB.
Is there a command for clear this cache?
I have an Nx monorepo (https://nx.dev).
It has a folder with Nx cache (./node_modules/.cache/nx/
).
Its size for now is over 3GB.
Is there a command for clear this cache?
Share Improve this question edited Oct 28, 2021 at 15:10 user17242583 asked Jan 27, 2021 at 9:19 Pax BeachPax Beach 2,7852 gold badges25 silver badges30 bronze badges5 Answers
Reset to default 147nx reset
clears the cache.
Docs on nx reset
: https://nx.dev/nx/reset#reset
Docs on the cache here: https://nx.dev/using-nx/caching#local-computation-caching
The above answer nx clear-cache
is for the jest cache. I would comment but no rep :)
Just delete the whole 'nx' cache folder:
rm -rf ./node_modules/.cache/nx
This works in the latest version as of today (February 12, 2022). I am uncertain why this is no longer in the CLI documentation despite evidence of it being there in the past: https://nx.dev/cli/clear-cache
nx clear-cache
There is not really any command to delete the Nx cache except to skip it or use the following command.
npx nx run build --skip-nx-cache
npx nx run test --skip-nx-cache
If size of the directory is your problem then may be running your node script as a cron job might be an option. In case, location of the directory is your concern then you also configure it and move it outside node_modules
like this.
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);
}
});
}
本文标签: javascriptHow to clear Nx cacheStack Overflow
版权声明:本文标题:javascript - How to clear Nx cache - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736823682a1954398.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论