[英]Does the npm cache speed up `npm install`?
Consider the following builds:考虑以下构建:
These two repositories are almost identical, with the only difference being the latter repository caches npm
via the setup-node
GitHub Action, whereas the former one does not.这两个存储库几乎相同,唯一的区别是后者存储库通过
setup-node
GitHub Action 缓存npm
,而前者没有。 In other words, the only difference between the repositories is at the .github/workflows/main
file:换句话说,存储库之间的唯一区别在于
.github/workflows/main
文件:
name: Build Pipeline
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '11'
# Following line is present only on the latter repository
cache: 'npm'
- run: npm install
- run: npm run build
Although the build at "setup-node-with-cache" successfully uses npm cache (as evident by the output of the Run actions/setup-node@v2
step), run time of Run npm install
step is almost the same as the corresponding step of the build at "setup-node-without-cache".尽管“setup-node-with-cache”的构建成功地使用了 npm 缓存(如
Run actions/setup-node@v2
步骤的 output 所示), Run npm install
步骤几乎相同在“setup-node-without-cache”处构建的步骤。
Isn't the run time of Run npm install
step of the build at "setup-node-with-cache" supposed to be significantly shorter than the corresponding step of the build at "setup-node-without-cache", since it is supposed to use the cached npm packages? Run npm install
步骤在“setup-node-with-cache”处的构建步骤的运行时间是否应该明显短于“setup-node-without-cache”处构建的相应步骤,因为它是应该使用缓存的 npm 包? Am I missing something here?我在这里错过了什么吗?
It really does not seem to be, at least on GitHub Actions.至少在 GitHub Actions 上似乎不是这样。 The workaround that I found is caching the actual
node_modules
folder, even though it is "not recommended".我发现的解决方法是缓存实际的
node_modules
文件夹,即使它“不推荐”。 Caching the actual node_modules
folder does speed up npm install
.缓存实际的
node_modules
文件夹确实加快了npm install
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.