sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
41 lines (34 loc) • 1.28 kB
text/typescript
const entryModule = `
// This file is auto-generated on 'sanity dev'
// Modifications to this file is automatically discarded
import {renderStudio} from "sanity"
import studioConfig from %STUDIO_CONFIG_LOCATION%
renderStudio(
document.getElementById("sanity"),
studioConfig,
{reactStrictMode: %STUDIO_REACT_STRICT_MODE%, basePath: %STUDIO_BASE_PATH%}
)
`
const noConfigEntryModule = `
// This file is auto-generated on 'sanity dev'
// Modifications to this file is automatically discarded
import {renderStudio} from "sanity"
const studioConfig = {missingConfigFile: true}
renderStudio(
document.getElementById("sanity"),
studioConfig,
{reactStrictMode: %STUDIO_REACT_STRICT_MODE%, basePath: %STUDIO_BASE_PATH%}
)
`
export function getEntryModule(options: {
reactStrictMode: boolean
relativeConfigLocation: string | null
basePath?: string
}): string {
const {reactStrictMode, relativeConfigLocation, basePath} = options
const sourceModule = relativeConfigLocation ? entryModule : noConfigEntryModule
return sourceModule
.replace(/%STUDIO_REACT_STRICT_MODE%/, JSON.stringify(Boolean(reactStrictMode)))
.replace(/%STUDIO_CONFIG_LOCATION%/, JSON.stringify(relativeConfigLocation))
.replace(/%STUDIO_BASE_PATH%/, JSON.stringify(basePath || '/'))
}