Change dist path for Sanity build in yarn/lerna monorepo

5 replies
Last updated: May 11, 2020
One more question: Are you able to change the dist path for the build? I'm using a yarn/lerna monorepo and would like to point it to the root dist folder - by default it is building to the package folder. And wanted to make a suggestion to add the build command to the package.json when generated with
sanity init
. I was pleasantly surprised that it worked with the existing monorepo out of the box.
AI Update

Great to hear the monorepo setup worked out of the box! Yes, you can absolutely change the dist path for the build.

Changing the Build Output Directory

According to the Sanity CLI build reference, the sanity build command accepts an optional OUTPUT_DIR argument:

sanity build [OUTPUT_DIR]

So you can simply specify your root dist folder:

sanity build ../../dist
# or whatever relative path points to your root dist folder

You can also add this to your package.json scripts in the Studio package:

{
  "scripts": {
    "build": "sanity build ../../dist"
  }
}

Additional Build Options

The build command also supports several useful flags:

  • --source-maps - Enable source maps (increases bundle size)
  • --no-minify - Skip minification (faster builds, larger bundles)
  • -y, --yes - Unattended mode for CI/CD

Regarding Your Suggestion

Your suggestion about adding the build command to package.json during sanity init is excellent feedback! Currently, when you run sanity init, it does create a package.json but the build script isn't always included by default. This would definitely be a helpful addition for developers, especially those working with monorepos.

You might want to share this feedback directly with the Sanity team through their community Slack or by opening a feature request on their GitHub repository. The team is quite responsive to community suggestions!

For monorepo setups specifically, you might also want to look into using workspace-level scripts or tools like Turborepo/Nx to manage builds across packages if you haven't already.

Show original thread
5 replies
Doesn't seem to be a config option for it, but you can do
sanity build <output-folder>
, I believe
I'll give it a try. Didn't see anything mentioned in
sanity help build
either.
omg
usage: sanity build [OUTPUT_DIR]
Or I'm just blind.
Yep, that worked!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?