Most tutorials and docs I've read utilize a structure like this for the Sanity's schema.js file:
import createSchema from 'part:@sanity/base/schema-creator'
import schemaTypes from 'all:part:@sanity/base/schema-type'
import blog from './documents/blog'
import author from './documents/author'
export default createSchema({
name: 'default',
types: schemaTypes.concat([
blog,
author,
]),
})
but I'd like to import the directory as a single source and I tried:
schema.js:
import createSchema from 'part:@sanity/base/schema-creator'
import schemaTypes from 'all:part:@sanity/base/schema-type'
import * as documents from './documents/'
export default createSchema({
name: 'default',
types: schemaTypes.concat([
documents,
]),
})
/documents/index.js:
export { default as author } from './author'
export { default as blog } from './blog'
and I tried:
import author from './author'
import blog from './blog'
export { author, blog }
Bringing all the individual files in schema.js works but when I try to change the file structure to reference one file I get an error of:
<unnamed_type_@_index_1>
from http://localhost:3333/desk/
.
Research
- Problem while exporting a function from another file in React
- What does "export default" do in JSX?
- Why es6 react component works only with "export default"?
- does not contain a default export even after being correctly imported in React
- ES6 exporting/importing in index file
- React - cannot export multiple files from index.js
- Export all files in
index.ts
In Sanity how can I export all my files within a directory and import them as one line in Sanity's schema?