分享快取
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
的存取權杖來連接你的工作區。
略過 Cloud
就像 --skip-nx-cache
會指示 Nx 不使用快取一樣,傳遞 --no-cloud
將會告知 Nx 不要使用 Nx Cloud。