Change dist path for Sanity build in yarn/lerna monorepo
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 folderYou 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 thread5 replies
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.