template-loader.ts#
8 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.
Reference#
fncreateSvelteCompilerPlugin(): import("rolldown").PluginCreates a rolldown plugin that compiles Svelte SFCs using svelte/compiler.
Creates a rolldown plugin that compiles Svelte SFCs using svelte/compiler.
Signature
function createSvelteCompilerPlugin(): import("rolldown").PluginReturns
import("rolldown").Plugin
fnisBareSpecifier(id: string): booleanWhether id is a bare specifier, and so resolvable at runtime rather than someth…
Whether id is a bare specifier, and so resolvable at runtime rather than something the template bundle has to inline.
Template bundles are written to <root>/.cache/og-images/ and imported from there, so Node resolves anything left external against the project's own node_modules. Relative and absolute imports still bundle, which is what a template actually needs — its own components travel with it.
Signature
export function isBareSpecifier(id: string): booleanParameters
-
idstring
Returns
boolean
variableconst OX_CONTENT_PACKAGE = /^@ox-content\/vite-plugin(\/.*)?$/Matches this package and every subpath it exports. A template's natural runtime…
Matches this package and every subpath it exports.
A template's natural runtime is whatever renders it, and for the framework-less kinds that is this package: renderToString, raw, when and each live at its root, and the JSX runtime under ./jsx-runtime. Inlining them instead drags the entire plugin — chokidar, fsevents and all — into the template bundle, which is what made importing it fail outright.
Signature
const OX_CONTENT_PACKAGE = /^@ox-content\/vite-plugin(\/.*)?$/fnresolveReactTemplate(templatePath: string, root: string): Promise<OgImageTemplateFn>Resolves a React (.tsx/.jsx) template via SSR. Bundles with rolldown (JSX trans…
Resolves a React (.tsx/.jsx) template via SSR.
Bundles with rolldown (JSX transform), then wraps with react-dom/server renderToReadableStream for async Server Component support.
Signature
async function resolveReactTemplate(templatePath: string, root: string): Promise<OgImageTemplateFn>Parameters
-
templatePathstring -
rootstring
Returns
Promise<OgImageTemplateFn>
fnresolveSvelteTemplate(templatePath: string, root: string): Promise<OgImageTemplateFn>Resolves a Svelte SFC template via SSR. Compiles the SFC with svelte/compiler (…
Resolves a Svelte SFC template via SSR.
Compiles the SFC with svelte/compiler (server mode + runes), bundles with rolldown, then wraps with svelte/server render().
Signature
async function resolveSvelteTemplate(templatePath: string, root: string): Promise<OgImageTemplateFn>Parameters
-
templatePathstring -
rootstring
Returns
Promise<OgImageTemplateFn>
fnresolveTemplate(options: ResolvedOgImageOptions, root: string): Promise<OgImageTemplateFn>Resolves the template function from options. Dispatches by file extension: - .v…
Resolves the template function from options.
Dispatches by file extension:
.vue→ Vue SFC (SSR via vue/server-renderer).svelte→ Svelte SFC (SSR via svelte/server).tsx/.jsx→ React Server Component (SSR via react-dom/server)- others → TypeScript template (direct function export)
Signature
export async function resolveTemplate(options: ResolvedOgImageOptions, root: string): Promise<OgImageTemplateFn>Parameters
-
optionsResolvedOgImageOptions -
rootstring
Returns
Promise<OgImageTemplateFn>
fnresolveTsTemplate(templatePath: string, options: ResolvedOgImageOptions, root: string): Promise<OgImageTemplateFn>Resolves a plain TypeScript template (existing behavior).
Resolves a plain TypeScript template (existing behavior).
Signature
async function resolveTsTemplate(templatePath: string, options: ResolvedOgImageOptions, root: string): Promise<OgImageTemplateFn>Parameters
-
templatePathstring -
optionsResolvedOgImageOptions -
rootstring
Returns
Promise<OgImageTemplateFn>
fntsTemplateBundleOptions(templatePath: string)Rolldown input options for a .ts template bundle. A .ts template is the framewo…
Rolldown input options for a .ts template bundle.
A .ts template is the framework-less kind, so it has no single runtime to externalize the way the .vue, .svelte and .tsx paths do — anything from node_modules is better resolved at import time than inlined. Nothing on this path has a compiler plugin, so nothing here needed bundling to be loadable in the first place.
Signature
export function tsTemplateBundleOptions(templatePath: string)Parameters
-
templatePathstring