Netlify is an incredibly easy to use and powerful host for static sites. While this blog is not hosted there, I did deploy it to Netlify, no joke in less than 5 minutes. With automatic deployment of updates on commit. Check em out.
Anyhow today I had a monorepo that has more than one site that I wanted to deploy to Netlify. The repo looked something like this:
Netlify supports this but it’s not super well documented how to accomplish it without a little sleuthing.
Monorepo support works by setting the
Base directory of each site’s configuration to point at the relative path to your site root:
As it says on the tin, this essentially sets the path to
cd to before starting the build commands. (Find it here:
But there’s one cool thing the description forgets to mention: You can also configure Netlify sites using a
netlify.toml file, making your configuration versioned in Git. This gets really useful to control the whole build stack from one place: configuring the build commands, redirects, setting up lambda functions. Netlify usually expects
netlify.toml in the root of the repository. However, the Base directory setting also changes where the
netlify.toml is expected to live. If we do this:
…then we get the lovely capability to both monorepo our sites, and also version our Netlify configuration. Awesome!