记录npm、yarn、pnpm清空代理、换源、清缓存等

1,981 阅读1分钟

删除代理

npm config delete proxy
npm config delete https-proxy
yarn config delete proxy
yarn config delete https-proxy
pnpm config delete proxy
pnpm config delete https-proxy

换源

淘宝镜像

npm config set registry https://registry.npmmirror.com
yarn config set registry https://registry.npmmirror.com
pnpm config set registry https://registry.npmmirror.com

官方源

npm config set registry https://registry.npmjs.org
yarn config set registry https://registry.yarnpkg.com
pnpm config set registry https://registry.npmjs.org

清缓存

npm cache clean --force
yarn cache clean --force

# pnpm
pnpm store prune
pnpm store path
rm -rf <PATH>

# pnpm 的可以简化为:
pnpm store prune
pnpm_store_path=$(pnpm store path)
rm -rf $pnpm_store_path

项目中快速清理的scripts

{
    "clean:pnpmstore": "pnpm store prune && pnpm_store_path=$(pnpm store path) && rm -rf $pnpm_store_path", // 清 pnpm store
    "clean:modules": "find . -type d -name 'node_modules' -prune -exec rm -rf '{}' +" // 删除项目中所有的 node_modules
}

打包时给node增大内存分配

{
    "build:test": "cross-env NODE_OPTIONS=--max_old_space_size=8192 vite build --mode test",
}