DEV Community

Julian Bustos
Julian Bustos

Posted on

Fastest way to start a new project with Nextjs & Sanity CMS & pnpm

  • Run
pnpm create next-app@latest my-new-app
Enter fullscreen mode Exit fullscreen mode
  • Select your nextjs options
  • cd into your app
cd my-new-app
Enter fullscreen mode Exit fullscreen mode
  • Create a new sanity project, embed the studio and create all the config files, from the cli
pnpm dlx sanity@latest init --create-project "My New App" --dataset production
Enter fullscreen mode Exit fullscreen mode
  • Select your configuration options for your sanity project as well as the route for the embedded studio.

Optional Steps

Add the scripts to generate types from your schemas and queries, to your package.json.

    "updateSchemaTypes": "sanity schema extract --enforce-required-fields",
    "generateQueryTypes": "sanity typegen generate",
    "generateTypes": "pnpm updateSchemaTypes && pnpm generateQueryTypes",

Enter fullscreen mode Exit fullscreen mode

Now you can run pnpm generateTypes every time you update your schemas or add a new query using defineQuery function from next-sanity, and you can get typed queries.

Now you're all setup and ready to go!

Happy coding!

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.