Do Deploy Previews work with a monorepo setup and GitHub's Pull Requests?

I’m currently on the fence about migrating to a monorepo setup. I love the Deploy Preview feature I get on GitHub’s Pull Requests. I found some information that building is possible: How to build projects in Monorepository that use shared components, Deploying Nx Monorepos which is awesome, but I couldn’t find any information if Deploy Previews are gonna work.

I’d love to know if this is available and if not whether it is something that is planned in the foreseeable future.

Thanks.

It will depend a lot on how you have things structured, @jcubed . This article describes the current state of our monorepo support:

There are definitely some missing pieces, for instance: https://github.com/netlify/build-image/issues/196 - so the answer is “your mileage will vary”, depending especially on:

  • can each build be self-contained within its subdirectory?
  • will each project even BE a subdirectory? That’s how our current support works best, though not how every person chooses to configure things.

My general advice would be:

  • if you can use per-project subdirectories
  • to try setting one up on a non-production branch, and seeing if you can link the branch to a separate site and get it to build correctly.

If you can, that’s a good indicator that the rest might work too! If you can’t (because e.g. it needs the node modules from the root of the repo installed), it might not be a good fit for our build system.

Thanks for answering. Does it make much of a difference if one were to use Nx instead of yarn/lerna? My understanding is that Nx uses root level node_modules while yarn workspaces use package-level node_modules?

Not sure, I have no personal experience nor even hearsay about how nx works. We don’t have any special support for it, so your best bet is still going to be “try and see”. You may not be aware that you can configure per-branch build commands in netlify.toml to keep things “clean” vs your production site:

  1. put netlify.toml inside of a base directory that is distinct from the repo root, where you’d like your build to start
  2. make a [context.yourbranchname] section with a command = "nx ..." for your special build command to be executed only for builds of a branch called yourbranchname (you can change those two to be a real branch name you want to use of course ;))