Monorepo projects depend a lot on the base directory build setting. However, this option makes our build system change to this directory and run all the relevant dependency install commands there. For
yarn this is a particular problem because when
yarn detects that it’s part of a workspace, it installs and hoists (moves to the root of the repo) all the package dependencies. Until recently, in these cases, we cached the
node_modules dependencies in the site base directory, but not the ones installed in the root
node_modules directory or any other package
node_modules directories. Because these other directories weren’t cached, they would have to be re-installed on every build, which can significantly increase build time.
We are changing that. We are introducing a change that will cache all the relevant
node_modules directories for
yarn workspace projects.
We’ll be rolling it out slowly to all of our builds but we’re super interested in collecting feedback and hearing from you folks directly. So, if you want to try this out, you can use the following environment variable (EDIT: This has now been rolled out to all of our builds so no action is required to start taking advantage of our caching improvements )
NETLIFY_YARN_WORKSPACES=true which will enable this feature.
On a first build execution you should see something similar to this in your logs:
Followed by this at the end of your build logs (notice we’re now caching multiple workspace directories)
On a follow up build execution the cache should start to take effect!
So, what do you think? We are looking forward to hearing back from you, so leave a comment below with your feedback!