Init Sanity project from CLI without creating files using custom template
Yes! There are actually a couple of options for initializing a Sanity project without creating all the Studio files:
The --bare Flag
As of Sanity CLI v3.9.0 (April 2023), the sanity init command supports a --bare flag that does exactly what you're looking for:
sanity init --bareor with npm create:
npm create sanity@latest -- --bareWhat --bare does:
- Skips the installation of a Sanity Studio
- Takes you through the project and dataset creation process
- Prints the project ID and dataset names to the console
- Perfect when you want to integrate with an existing application or have your own Studio code ready
The --env Flag
The same update also introduced the --env flag, which is useful when setting up environment variables:
sanity init --envThis flag:
- Detects the framework used in your current directory
- Creates a
.envfile with the correct prefix for environment variables - You can specify a custom path like
--env .env.local.example
Using with Custom Templates
While the documentation doesn't explicitly cover using --bare with custom templates created via sanity-template, you can combine these approaches:
- Use
--bareto create just the project/dataset - Then use your custom template or existing Studio code
- Configure it with the project ID that was printed to the console
The sanity projects create Command
For even more control, you can use the sanity projects create command directly to create just a project without any Studio files at all, then set up your Studio or application separately.
These flags are particularly useful when you're integrating Sanity into an existing application, working with custom templates, or when you only need the Content Lake capabilities without a full Studio setup.
Show original thread13 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.