Skip to content

template-loader.ts#

View Markdown

Source

8 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.

8 symbols 7 functions 1 variables 11 parameters 6 returns

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").Plugin

View source

Returns

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): boolean

View source

Parameters

  • id string

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(\/.*)?$/

View source

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>

View source

Parameters

  • templatePath string
  • root string

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>

View source

Parameters

  • templatePath string
  • root string

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>

View source

Parameters

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>

View source

Parameters

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)

View source

Parameters

  • templatePath string