Deploy subfolders in monorepo

Hi there Netlify community,

I understand Netlify now supports monorepos, which seems to be a perfect fit for my requirements:

I have a git repository containing multiple git submodules, each of them is a different gatsbyjs website. I’d ultimately like to ensure these submodules are deployed in their respective separate subfolders, rather than on the website root.

This is what my netlify.toml currently looks like:

[build]
  base    = "nunogt"
  publish = "nunogt/public/"
  command = "gatsby build"

This compiles and deploys fine, but as per https://docs.netlify.com/configure-builds/common-configurations/#monorepos, I’d expect this build to be made available in https://devopspt.netlify.app/nunogt/ rather than the root https://devopspt.netlify.app/.

I’ve studied the netlify reference configuration file to check whether I’m missing something, but can’t really see any other clues there that would help me achieve this goal.

The fact that the base and publish attributes are within the build section does suggest these attributes are not designed for anything outside the build context, but if I could get an authoritative answer on this from netlify that would be much appreciated.

Thanks in advance

The base path is used only for setting the root of the project, that is, it’s the path where package.json, netlify.toml, etc. would be searched for.

Publish path is the root of the website. So, if you publish nunogt/public, it would be available at the root of the domain. The only way to make it available at https://devopspt.netlify.app/nunogt/ is to have a folder named nunogt with all the files inside the publish folder.

So, what you’re looking to achieve, that is, build multiple Gatsby websites and publish them all in their sub-folders might not be possible easily. You might have to try getting creative with your build command like cd <path to first website> && gatsby build && mv public ../ && cd <path to second website> && gatsby build... and so on. It’s just a guess and might not even work.

The only other way would be to build locally, move the files in the structure you want and either manually upload the build to Netlify or use a repo to push the pre-built files there.

It would be interesting to see if there are better ways of doing this.

1 Like

Yeah I’m now pretty much convinced this workflow is not going to be trivial to implement, certainly not without hijacking some of Netlify’s build system expectations like you’ve described. I’ll continue exploring. Thanks for the reply @hrishikesh, appreciate your answer.