CircleCI での Yarn (npm の代替) の使用

Yarn は、JavaScript 用のオープンソース パッケージ マネージャーです。 The packages it installs can be cached. This can potentially speed up builds but, more importantly, can reduce errors related to network connectivity.

CircleCI での Yarn の使用方法

Yarn might already be installed in your build environment if you are using the docker executor. With Pre-built CircleCI Docker Images, the NodeJS image (circleci/node) already has Yarn preinstalled. If you are using one of the other language images such as circleci/python or circleci/ruby, there are two image variants that will include Yarn as well as NodeJS. These would be the -node and -node-browsers image variants. For example, using the Docker image circleci/python:3-node will give you a Python build environment with Yarn and NodeJS installed.

If you’re using your own Docker image base or the macos, windows or machine executors, you can install Yarn by following the official instructions from Yarn Docs. The Yarn Docs provide several installation methods depending on what machine executor you might be using. For example, you can install on any unix-like environment using the following curl command.

curl -o- -L https://yarnpkg.com/install.sh | bash

キャッシュ

Yarn packages can be cached to improve CI build times.

An example for Yarn 2:

If you’re using Yarn 2.x without Zero Installs, you can do something like this:

#...
      - restore_cache:
          name: Restore Yarn Package Cache
          keys:
            - yarn-packages-{{ checksum "yarn.lock" }}
      - run:
          name: Install Dependencies
          command: yarn install --immutable
      - save_cache:
          name: Save Yarn Package Cache
          key: yarn-packages-{{ checksum "yarn.lock" }}
          paths:
            - ~/.cache/yarn
#...

An example for Yarn 1.x:

#...
      - restore_cache:
          name: Restore Yarn Package Cache
          keys:
            - yarn-packages-{{ checksum "yarn.lock" }}
      - run:
          name: Install Dependencies
          command: yarn install --frozen-lockfile --cache-folder ~/.cache/yarn
      - save_cache:
          name: Save Yarn Package Cache
          key: yarn-packages-{{ checksum "yarn.lock" }}
          paths:
            - ~/.cache/yarn
#...

See also

Caching Dependencies



ドキュメントの改善にご協力ください

このガイドは、CircleCI の他のドキュメントと同様にオープンソースで、GitHub で使用できます。 ご協力いただき、ありがとうございます。


クリエイティブ・コモンズ・ライセンス
CircleCICircleCI ドキュメントは、クリエイティブ・コモンズの表示--非営利-継承 4.0 国際ライセンス に基づいてライセンス供与されています。