nrwl / nx-incremental-large-repo

67 stars 35 forks source link

Incremental Build && Fast Serve

This project has an application composed out 44 libraries (more than 2000 components). If you run nx dep-graph, you will see the following:

Note: this is experimental right now and will be released in Nx v11. Check out our roadmap.

Two Applications

There are two applications in the repo: app0 and app1. They are identical. They import the same libraries. The only difference is app1 is built using normal webpack builder, where all the libraries are built from source and app0 is built differently: every library here is built in its own process.

Serving App1

Serving App0

Why is running nx serve app0 so fast? Because the results of building most libraries are retrieved from the Nx Cloud cache (or your local cache). If you don't have the cache, rebuilding everything takes about 1 minute. Most of the time, however, you are getting the artifacts from Nx Cloud because your CI or your co-workers already built the version of the repo you are working against.

Why is making an incremental change takes 15 seconds?

Given that, by providing a custom builder, we could cut the incremental change time down to 10 seconds.

Bigger Apps

If we double the app size to 4000 components, the following will be the case:

So app0 scales a lot better as the codebase grows. The initial nx serve will only take a few seconds regardless of the size of the app. In this repo's example, the incremental change of app0 is somewhat slower, but the difference is getting less substantial as the app grows. And by using a builder that simply invokes ngc instead of ngpackgr, it's possible to make the incremental change of app0 faster than app1 for any large app.

Testing and Linting

How does it work?

This works, thanks to a combination of existing and newly introduced Nx features:

Keep an eye on our Twitter account and our blog for a more in-depth explanation once v11 is released.

Try it!