How to configure Sanity Studio webpack to handle .odt font file imports?
I need to first clarify something important: .odt files are OpenDocument Text files (document format, like Word documents), not font files. This is quite unusual to import into a JavaScript/React library that would be used in Sanity Studio.
If your library is genuinely trying to import .odt document files (not .otf font files), you'll need to configure Sanity Studio's Vite build to handle these files. Let me address both possibilities since the use case is uncommon:
If You Meant .otf Font Files
If you're actually dealing with .otf (OpenType Font) files, you can configure Sanity Studio v3 to handle them by customizing the Vite configuration. Create or modify a sanity.cli.js file in your Studio root:
// sanity.cli.js
import {defineCliConfig} from 'sanity/cli'
export default defineCliConfig({
api: {
projectId: 'your-project-id',
dataset: 'your-dataset'
},
vite: {
assetsInclude: ['**/*.otf', '**/*.woff', '**/*.woff2', '**/*.ttf']
}
})The assetsInclude option tells Vite to treat these file extensions as static assets that should be copied to the build output.
If You Actually Need .odt Document Files
If your library truly needs to import .odt files (document format), you'd use a similar approach:
// sanity.cli.js
import {defineCliConfig} from 'sanity/cli'
export default defineCliConfig({
api: {
projectId: 'your-project-id',
dataset: 'your-dataset'
},
vite: {
assetsInclude: ['**/*.odt'],
build: {
assetsInlineLimit: 0 // Prevent inlining of these files
}
}
})However, I'd strongly recommend reconsidering your architecture—importing document files directly into client-side code is unusual and may cause performance issues. Consider instead:
- Uploading to Sanity's asset pipeline and referencing them via URLs
- Storing in a public/static folder and referencing via public URLs
- Converting the data to a format more suitable for JavaScript (JSON, etc.)
Important Note About Studio v3
Since Sanity Studio v3 uses Vite (not webpack), the old webpack-based configuration methods you may have seen referenced (part:@sanity/base/webpack-config) from Studio v2 no longer work. All build customization now goes through the Vite configuration in sanity.cli.js.
The configuration file approach I've shown above is the current way to extend the build tooling in Studio v3.
Could you clarify what your library is actually trying to do with these files? If it's font files, the .otf solution above should work. If it's actual document files, you may need a different architectural approach altogether.
Show original thread6 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.