-
Notifications
You must be signed in to change notification settings - Fork 19
Feature request: Sanity v3 support #272
Comments
I agree that proper Sanity v3 support would be great! In the meantime, here is what I did to have the tool work in Sanity v3. The idea is to have an // src/schemas/index.ts
const schemas: SchemaTypeDefinition[] = [
personDoc,
clientDoc,
projectDoc,
jobDoc,
newsItem,
articleDoc,
]
export default schemas
// sanity.config.ts
import schemas from './src/schemas'
//... later in the config
schema: { types: schemas } Along with that, you'll also need to create a import { SanityCodegenConfig } from 'sanity-codegen'
const config: SanityCodegenConfig = {
schemaPath: './src/schemas/index',
// Uncomment below to change output path
// outputPath: './src/utils/types/schema/generated-schema-types.ts',
babelOptions: {
// Plugins are copy pasted from https://github.com/ricokahler/sanity-codegen/blob/main/src/cli.ts
// Only the `babel-plugin-transform-vite-meta-env` plugin is added
plugins: [
// used to resolve and no-op sanity's part system
[
'module-resolver',
{
root: ['.'],
alias: {
'part:@sanity/base/schema-creator': 'sanity-codegen/schema-creator-shim',
'all:part:@sanity/base/schema-type': 'sanity-codegen/schema-type-shim',
'part:@sanity/base/schema-type': 'sanity-codegen/schema-type-shim',
'^part:.*': 'sanity-codegen/no-op',
'^config:.*': 'sanity-codegen/no-op',
'^all:part:.*': 'sanity-codegen/no-op',
},
},
],
// used to resolve css module imports that are allowed in sanity projects
'css-modules-transform',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-numeric-separator',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator',
'babel-plugin-transform-vite-meta-env', // ADDED
],
},
}
export default config Also be sure to install the So far, I didn't encounter any bug or issue with this approach. If I do, I'll update this comment with my problems. Hopefully this helps a few people out there 😉 UPDATE: I actually ran into one really annoying issue. I use environment variables throughout the studio, which uses |
Hi, const schemas = [
...schemaTypes
]
export default schemas At the end of my schemas/index.ts |
@alexbchr Do you know what errors you encountered when trying the codegen in V3? I'm getting this error with the content of your
It gets stuck on the
|
@thomasblom Sorry for not being more helpful than that, but I don't exactly remember the error I was getting, although I can assure you it was not the same one as yours. When writing the answer in this thread, I do remember that we were on one of the early betas or RCs of V3 and we didn't update since then as we moved on to a separate project. The fact that |
hi all. i am alive and the upcoming 1.0 branch is the one that will support v3 (and it will only support v3). check it out now if you'd like to experiment but it's still not stable. the current main branch will not support v3 |
I got this error while using alpha, Please how do I fix this?
|
@jomefavourite I fixed that by adding a name to the
|
Okay, thanks |
Hi, we're loving this tool but after upgrading Sanity to its v3
dev-preview
, it now gives an errorTypeError: types.filter is not a function
, presumably because the config entry point is now different.I posted a question about whether v3 will feature type exporting here: sanity-io/sanity#3343 (comment) -- it's still in development so potentially could be something they could add.
If it helps you jump in to make a v3-compatible version, here's how we have our project set up:
sanity.config.ts
Thanks for considering it!
The text was updated successfully, but these errors were encountered: