Use Remote Caching
The computation cache provided by Nx can be distributed across multiple machines. You can either build an implementation of the cache or use Nx Cloud. Nx Cloud is an app that provides a fast and zero-config implementation of distributed caching. It's completely free for OSS projects and for most closed-sourced projects (read more here).
In this diagram, Teika runs the build once on his machine, then CI, Kimiko and James can use the cached artifact from Teika instead of re-executing the same work.
Connecting Your Workspace to Your Nx Cloud Account
You can connect your workspace to Nx Cloud by running:
❯
npx nx connect-to-nx-cloud
To see the remote cache in action, run:
~/workspace❯
nx build header && nx reset && nx build header
1> nx run header:build
2
3> header@0.0.0 build
4> rimraf dist && rollup --config
5
6src/index.tsx → dist...
7created dist in 786ms
8
9 —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
10
11 > NX Successfully ran target build for project header (2s)
12
13 See logs and investigate cache misses at https://cloud.nx.app/runs/k0HDHACpL8
14
15
16 > NX Resetting the Nx workspace cache and stopping the Nx Daemon.
17
18 This might take a few minutes.
19
20
21 > NX Daemon Server - Stopped
22
23
24 > NX Successfully reset the Nx workspace.
25
26
27> nx run header:build [remote cache]
28
29
30> header@0.0.0 build
31> rimraf dist && rollup --config
32
33
34src/index.tsx → dist...
35created dist in 786ms
36
37 —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
38
39 > NX Successfully ran target build for project header (664ms)
40
41 Nx read the output from the cache instead of running the command for 1 out of 1 tasks.
42
43 Nx Cloud made it possible to reuse header: https://nx.app/runs/P0X6ZGTkqZ
44
Claim your Nx Cloud Workspace
After you have enabled Nx Cloud in your workspace, you will see the following:
1> NX NOTE Nx Cloud has been enabled
2
3 Your workspace is currently public. Anybody with code access
4 can view the workspace on nx.app.
5
6 You can connect the workspace to your Nx Cloud account at
7 https://nx.app/orgs/workspace-setup?accessToken=N2Y3NzcyO...
8 (You can do this later.)
9
Click on this link to associate the workspace with your Nx Cloud account. If you don't have an Nx Cloud account, you can create one on the spot.
After you claim your workspace, you will be able to manage permissions, create access tokens, set up billing, and so forth.
You will also see an interactive tutorial helping you explore distributed caching and the Nx Cloud user interface.
If you lose this link, you can still connect your workspace to Nx Cloud. Go to nx.app, create an account, and connect your workspace using the access token from nx.json
.
Skipping Cloud
Similar to how --skip-nx-cache
will instruct Nx not to use the local cache, passing --no-cloud
will tell Nx not to use the remote cache from Nx Cloud.