npm-cache

概要

npm cache add <tarball file>
npm cache add <folder>
npm cache add <tarball url>
npm cache add <name>@<version>

npm cache clean [<path>]
aliases: npm cache clear, npm cache rm

npm cache verify

描述

用于添加,列出或清除npm缓存目录。

  • add:将指定的包数据添加到本地缓存。

  • clean: 从缓存目录中删除所有数据。

  • verify:验证缓存目录的内容,验证缓存索引和所有缓存数据的完整性。

细节

缓存数据生成到默认全局缓存目录(如下配置cache)下的一个_cacache文件夹中。可以通过如下方式查看全局缓存目录。

> npm config get cache

除了回收磁盘空间之外,不应该有任何理由清除缓存,所以clean都需要加上--force运行。

npm不会自行删除数据:缓存目录下将随着新包的安装而增长。有了缓存,以便于下次再安装相同包时直接从缓存中复用,加速安装。

配置

cache

Default: ~/.npm on Posix, or %AppData%/npm-cache on Windows.

全局缓存目录的默认路径。当然也可以为一次操作重新指定缓存目录的路径。

> npm cache add npm-demos-test --cache="e:\root\npmcache\"

若不希望每次操作都用--cache来指定新的缓存目录,有一种釜底抽薪的办法。

> npm config set cache "e:\root\npmcache\"

这样就从本质上更改了全局缓存目录,以后安装及其其他操作,都以新指定的缓存目录为准。

results matching ""

    No results matching ""