メインコンテンツへスキップ

キャッシュの共有

Lernaが提供する計算キャッシュは、複数のマシンに分散させることができます。キャッシュの実装を構築するか、Nx Cloudを使用できます。Nx Cloudは、分散キャッシュの高速でゼロ構成の実装を提供するアプリです。OSSプロジェクトやほとんどのクローズドソースプロジェクトでは完全に無料です(詳細はこちら)。

ワークスペースをNx Cloudに接続するには、次を実行します。

npx nx connect-to-nx-cloud
ターミナル出力
✔ Enable distributed caching to make your CI faster · Yes

> NX Generating @nrwl/nx-cloud:init

UPDATE nx.json

> NX Distributed caching via Nx Cloud has been enabled

In addition to the caching, Nx Cloud provides config-free distributed execution,
UI for viewing complex runs and GitHub integration. Learn more at https://nx.app

Your workspace is currently unclaimed. Run details from unclaimed workspaces can be viewed on cloud.nx.app by anyone
with the link. Claim your workspace at the following link to restrict access.

https://cloud.nx.app/orgs/workspace-setup?accessToken=YOURACCESSTOKEN

リモートキャッシュの動作を確認するには、次を実行します。

lerna run build --scope=header && nx reset && lerna run build --scope=header
ターミナル出力
> lerna run build --scope=header

> header@0.0.0 build
> rimraf dist && rollup --config

src/index.tsx → dist...
created dist in 786ms

—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

Lerna (powered by Nx) Successfully ran target build for project header (2s)

See logs and investigate cache misses at https://cloud.nx.app/runs/k0HDHACpL8


> NX Resetting the Nx workspace cache and stopping the Nx Daemon.

This might take a few minutes.


> NX Daemon Server - Stopped


> NX Successfully reset the Nx workspace.


> lerna run build --scope=header [remote cache]


> header@0.0.0 build
> rimraf dist && rollup --config


src/index.tsx → dist...
created dist in 786ms

—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

Lerna (powered by Nx) Successfully ran target build for project header (664ms)

Nx read the output from the cache instead of running the command for 1 out of 1 tasks.

Nx Cloud made it possible to reuse header: https://nx.app/runs/P0X6ZGTkqZ

ワークスペースをNx Cloudアカウントに接続する

ワークスペースでNx Cloudを有効にすると、次のようになります。

>  NX   NOTE  Nx Cloud has been enabled

Your workspace is currently public. Anybody with code access
can view the workspace on nx.app.

You can connect the workspace to your Nx Cloud account at
https://nx.app/orgs/workspace-setup?accessToken=N2Y3NzcyO...
(You can do this later.)

このリンクをクリックして、ワークスペースをNx Cloudアカウントに関連付けます。Nx Cloudアカウントをお持ちでない場合は、その場で作成できます。

ワークスペースを要求すると、アクセス許可の管理、アクセストークンの作成、課金の設定などを行うことができるようになります。

また、分散キャッシュとNx Cloudのユーザーインターフェイスを探索するのに役立つインタラクティブなチュートリアルも表示されます。

このリンクを紛失した場合でも、ワークスペースをNx Cloudに接続できます。nx.appにアクセスしてアカウントを作成し、nx.jsonのアクセストークンを使用してワークスペースを接続します。

クラウドをスキップする

--skip-nx-cacheがNxにキャッシュを使用しないように指示するのと同様に、--no-cloudを渡すとNxにNx Cloudを使用しないように指示します。