如何从 Github 操作步骤中验证 npm install 是否从 npm 缓存中安装已安装的模块?
默认情况下不会有 npm 缓存。它旋转的盒子每次都会是新的。您可以使用 actions/cache 配置一个。它看起来像:
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Clone project
uses: actions/checkout@v3
- name: Install node
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: ./node_modules
key: modules-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci
- name: Build
run: npm run build
要验证它,您可以运行一次构建,然后再次运行相同的构建。后续运行应该会更快。