Only Build, Test, Lint Once
When running Nx without Nx Cloud, a computation cache is created on your local machine to make the developer experience faster. This allows you to not waste time re-building, re-testing, re-linting, or any number of other actions you might take on code that hasn’t changed. Since the cache is stored locally, you are the only member of your team that can take advantage of these instant commands.
Nx Cloud allows this cache to be shared across your entire organization, meaning that any cacheable operation completed on your workspace only needs to be run once.
The time savings that this can provide your team are drastic. This blog post explains how such a simple concept can have a massive impact on productive time for you and your team.
To enable the cache:
Connect your workspace to Nx Cloud
Make sure the cacheableOperations array in nx.json contains all the targets you want to cache.
Make sure you configure an Nx Cloud access token.
If you configure a read-write access token in nx.json or via the NX_CLOUD_ACCESS_TOKEN env variable, any time you run a command the Nx CLI will upload the artifacts to the cloud.
If you configure the read-only access token, the Nx CLI will try to download cached artifacts from the Nx Cloud, but won't try to store them.
It's common to use a single read-write access token for small workspaces, and the combination of a read-write token for CI and a read-only token for local development for large workspaces.
See the Configuring the Cloud Runner section for more information on how to configure and troubleshoot the cache.
To make sure the cache is on:
Run a cacheable command (e.g., nx build yourappname). If you click on the Nx Cloud link, you will see that the task was a cache miss.
Rerun the same command. If you click on the link again, you will see that the task was a local cache hit.
Delete your local cache. By default, it's located in node_modules/.cache. After deleting, rerun the same command again. This time, if you click on the Nx Cloud link, you will see an icon of a cloud next to the task, indicating that the artifacts have been fetched from the cloud.
Caching Inner Commands
By default, Nx Cloud is not used for Nx commands invoked from within other Nx commands. For example, in the following configuration build1 and build2 won't be cached individually.
"commands": ["nx build1 proj", "nx build2 proj"]
If you would like them to be cached individually, and a separate run to be created for each of them, add the following:
"commands": ["NX_CLOUD=true nx build1 proj", "NX_CLOUD=true nx build2 proj"]