验证 npm install 是否从缓存安装

问题描述 投票:0回答:1

如何从 Github 操作步骤中验证 npm install 是否从 npm 缓存中安装已安装的模块?

node.js npm github-actions npm-install npm-cache
1个回答
0
投票

默认情况下不会有 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

要验证它,您可以运行一次构建,然后再次运行相同的构建。后续运行应该会更快。

© www.soinside.com 2019 - 2024. All rights reserved.