ℹ️ The Starter uses Sanity Studio v3. For the previous v2 version, have a look at the
studio-v2
branch
Opinionated monorepo starter based on Nuxt 3 and Sanity v3. Look at the Nuxt 3 documentation
and the Sanity documentation
to learn more.
Preview: https://sanity-nuxt-3-starter.netlify.app 👀
- Monorepo using PNPM Workspaces
- Sanity Studio v3 React Backend (in /studio)
- Nuxt 3 Frontend (in /web)
- Vite Module Bundler
- Pinia Store
- Linting with ESLint
- Code Formatting with Prettier
- Lazyloading with LazySizes
- Studio using Mux for videos
- Configured for Netlify Hosting
-
Install the project as a nuxt template
npx nuxi init -t gh:jjjuulliiaann/sanity-nuxt-3-starter my-project-title
-
If not installed, you can install the sanity cli globally
npm install --global sanity@latest
-
Create a new Sanity project (from root):
npm create sanity@latest
Follow the steps until asked for the "Project output path". Enter
Ctrl+C
to abort as we already have a studio folder.(Currently it seems not to be possible to create a new sanity project using the cli without installing a new studio folder)
-
Get the ID of your newly created project by listing your projects:
sanity projects list
-
Create a
.env
file from.env.template
in both/studio
and/web
and fill in the project ID and dataset. -
Rename project in
package.json
and your studio instudio/sanity.config.js
-
On sanity.io/manage add
http://localhost:3000
to the CORS origins (allow Credentials for Previews) -
Install dependencies (from root)
pnpm i --shamefully-hoist
-
Start developing on localhost:3000 (Nuxt frontend) and localhost:3333 (Sanity studio) (from root)
pnpm dev
-
In Netlify add two separate sites with "studio" / "web" as the base directories. The rest of the build settings is handled automatically (and by the
studio/netlify.toml
file). -
You will need to add environment variables used in your .env files to Netlify as well.
-
API Access: You have to add all origins that should have access to your Sanity dataset (like http://localhost:3333 or your netlify url) the to the API settings in your
Sanity Account
-
To install updates for the Sanity studio:
cd studio sanity upgrade cd .. pnpm i --shamefully-hoist
To upgrade Nuxt 3 to the latest release, use the npx nuxi upgrade
command.
To update manually: Bump nuxt
dependency to the new version and then use npx nuxi@latest cleanup
to cleanup any local caches.
- All documents defined in
config/views.js
have a preview tab in the Studio - The production urls for those documents are resolved with the
resolveProductionUrl
function inconfig/views.js
- The "Open preview" button in the studio context menu is defined in
sanity.config.js
usingresolveProductionUrl
- The studio uses the
sanity-plugin-iframe-pane
to show the page inside a preview pane
- A separate Sanity client named
preview
is defined innuxt.config.js
. - You have to allow credentials for the frontend URL in your Sanity API settings to access unpublished data from Sanity.
- If the url contains the
preview
query, theuseSanityData
composable uses the preview client for fetching data