# template-loader.ts

**[Source](https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/og-image/template-loader.ts)**

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

<div class="ox-api-stats" aria-label="API reference summary">
<span class="ox-api-stat">
  <strong>8</strong>
  <span>symbols</span>
</span>
<span class="ox-api-stat">
  <strong>7</strong>
  <span>functions</span>
</span>
<span class="ox-api-stat">
  <strong>1</strong>
  <span>variables</span>
</span>
<span class="ox-api-stat">
  <strong>11</strong>
  <span>parameters</span>
</span>
<span class="ox-api-stat">
  <strong>6</strong>
  <span>returns</span>
</span>
</div>

## Reference

<div class="ox-api-controls" data-ox-api-target=".ox-api-entry" role="toolbar" aria-label="Reference display controls">
<button type="button" class="ox-api-controls__button" data-ox-api-toggle="expand">Open all</button>
<button type="button" class="ox-api-controls__button" data-ox-api-toggle="collapse">Close all</button>
</div>

<details id="createsveltecompilerplugin" class="ox-api-entry">
  <summary><span class="ox-api-entry__kind">fn</span><span class="ox-api-entry__summary-main"><code class="ox-api-entry__signature ox-api-entry__signature--highlighted language-typescript">createSvelteCompilerPlugin(): import(&quot;rolldown&quot;).Plugin</code><span class="ox-api-entry__description">Creates a rolldown plugin that compiles Svelte SFCs using svelte/compiler.</span><span class="ox-api-entry__meta"><span class="ox-api-badge">returns import(&quot;rolldown&quot;).Plugin</span></span></span></summary>
  <div class="ox-api-entry__body">
<div class="ox-api-entry__prose">
<p>Creates a rolldown plugin that compiles Svelte SFCs using svelte/compiler.</p>
</div>
<div class="ox-api-entry__section ox-api-entry__section--signature">
<h4>Signature</h4>
<pre><code class="language-typescript">function createSvelteCompilerPlugin(): import(&quot;rolldown&quot;).Plugin</code></pre>
</div>
<p class="ox-api-entry__source"><a class="ox-api-entry__source-link" href="https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/og-image/template-loader.ts#L209-L235" target="_blank" rel="noopener noreferrer">View source<span class="ox-api-entry__source-icon" aria-hidden="true"></span></a></p>
<div class="ox-api-entry__section ox-api-entry__section--returns">
<h4>Returns</h4>
<div class="ox-api-entry__return">
  <code class="ox-api-entry__return-type">import(&quot;rolldown&quot;).Plugin</code>
</div>
</div>
  </div>
</details>

<details id="isbarespecifier" class="ox-api-entry">
  <summary><span class="ox-api-entry__kind">fn</span><span class="ox-api-entry__summary-main"><code class="ox-api-entry__signature ox-api-entry__signature--highlighted language-typescript">isBareSpecifier(id: string): boolean</code><span class="ox-api-entry__description">Whether id is a bare specifier, and so resolvable at runtime rather than someth…</span><span class="ox-api-entry__meta"><span class="ox-api-badge">1 param</span><span class="ox-api-badge">returns boolean</span></span></span></summary>
  <div class="ox-api-entry__body">
<div class="ox-api-entry__prose">
<p>Whether <code>id</code> is a bare specifier, and so resolvable at runtime rather than something the template bundle has to inline.</p>
<p>Template bundles are written to <code>&lt;root&gt;/.cache/og-images/</code> and imported from there, so Node resolves anything left external against the project&#39;s own <code>node_modules</code>. Relative and absolute imports still bundle, which is what a template actually needs — its own components travel with it.</p>
</div>
<div class="ox-api-entry__section ox-api-entry__section--signature">
<h4>Signature</h4>
<pre><code class="language-typescript">export function isBareSpecifier(id: string): boolean</code></pre>
</div>
<p class="ox-api-entry__source"><a class="ox-api-entry__source-link" href="https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/og-image/template-loader.ts#L89-L95" target="_blank" rel="noopener noreferrer">View source<span class="ox-api-entry__source-icon" aria-hidden="true"></span></a></p>
<div class="ox-api-entry__section ox-api-entry__section--params">
<h4>Parameters</h4>
<ul class="ox-api-entry__params">
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">id</code>
    <code class="ox-api-entry__param-type">string</code>
  </div>
</li>
</ul>
</div>
<div class="ox-api-entry__section ox-api-entry__section--returns">
<h4>Returns</h4>
<div class="ox-api-entry__return">
  <code class="ox-api-entry__return-type">boolean</code>
</div>
</div>
  </div>
</details>

<details id="ox_content_package" class="ox-api-entry">
  <summary><span class="ox-api-entry__kind">variable</span><span class="ox-api-entry__summary-main"><code class="ox-api-entry__signature ox-api-entry__signature--highlighted language-typescript">const OX_CONTENT_PACKAGE = /^@ox-content\/vite-plugin(\/.*)?$/</code><span class="ox-api-entry__description">Matches this package and every subpath it exports. A template&#39;s natural runtime…</span></span></summary>
  <div class="ox-api-entry__body">
<div class="ox-api-entry__prose">
<p>Matches this package and every subpath it exports.</p>
<p>A template&#39;s natural runtime is whatever renders it, and for the framework-less kinds that is this package: <code>renderToString</code>, <code>raw</code>, <code>when</code> and <code>each</code> live at its root, and the JSX runtime under <code>./jsx-runtime</code>. Inlining them instead drags the entire plugin — chokidar, fsevents and all — into the template bundle, which is what made importing it fail outright.</p>
</div>
<div class="ox-api-entry__section ox-api-entry__section--signature">
<h4>Signature</h4>
<pre><code class="language-typescript">const OX_CONTENT_PACKAGE = /^@ox-content\/vite-plugin(\/.*)?$/</code></pre>
</div>
<p class="ox-api-entry__source"><a class="ox-api-entry__source-link" href="https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/og-image/template-loader.ts#L78" target="_blank" rel="noopener noreferrer">View source<span class="ox-api-entry__source-icon" aria-hidden="true"></span></a></p>
  </div>
</details>

<details id="resolvereacttemplate" class="ox-api-entry">
  <summary><span class="ox-api-entry__kind">fn</span><span class="ox-api-entry__summary-main"><code class="ox-api-entry__signature ox-api-entry__signature--highlighted language-typescript">resolveReactTemplate(templatePath: string, root: string): Promise&lt;OgImageTemplateFn&gt;</code><span class="ox-api-entry__description">Resolves a React (.tsx/.jsx) template via SSR. Bundles with rolldown (JSX trans…</span><span class="ox-api-entry__meta"><span class="ox-api-badge">2 params</span><span class="ox-api-badge">returns Promise&lt;OgImageTemplateFn&gt;</span></span></span></summary>
  <div class="ox-api-entry__body">
<div class="ox-api-entry__prose">
<p>Resolves a React (.tsx/.jsx) template via SSR.</p>
<p>Bundles with rolldown (JSX transform), then wraps with react-dom/server renderToReadableStream for async Server Component support.</p>
</div>
<div class="ox-api-entry__section ox-api-entry__section--signature">
<h4>Signature</h4>
<pre><code class="language-typescript">async function resolveReactTemplate(templatePath: string, root: string): Promise&lt;OgImageTemplateFn&gt;</code></pre>
</div>
<p class="ox-api-entry__source"><a class="ox-api-entry__source-link" href="https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/og-image/template-loader.ts#L243-L313" target="_blank" rel="noopener noreferrer">View source<span class="ox-api-entry__source-icon" aria-hidden="true"></span></a></p>
<div class="ox-api-entry__section ox-api-entry__section--params">
<h4>Parameters</h4>
<ul class="ox-api-entry__params">
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">templatePath</code>
    <code class="ox-api-entry__param-type">string</code>
  </div>
</li>
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">root</code>
    <code class="ox-api-entry__param-type">string</code>
  </div>
</li>
</ul>
</div>
<div class="ox-api-entry__section ox-api-entry__section--returns">
<h4>Returns</h4>
<div class="ox-api-entry__return">
  <code class="ox-api-entry__return-type">Promise&lt;<a href="./og-image-types.md#ogimagetemplatefn">OgImageTemplateFn</a>&gt;</code>
</div>
</div>
  </div>
</details>

<details id="resolvesveltetemplate" class="ox-api-entry">
  <summary><span class="ox-api-entry__kind">fn</span><span class="ox-api-entry__summary-main"><code class="ox-api-entry__signature ox-api-entry__signature--highlighted language-typescript">resolveSvelteTemplate(templatePath: string, root: string): Promise&lt;OgImageTemplateFn&gt;</code><span class="ox-api-entry__description">Resolves a Svelte SFC template via SSR. Compiles the SFC with svelte/compiler (…</span><span class="ox-api-entry__meta"><span class="ox-api-badge">2 params</span><span class="ox-api-badge">returns Promise&lt;OgImageTemplateFn&gt;</span></span></span></summary>
  <div class="ox-api-entry__body">
<div class="ox-api-entry__prose">
<p>Resolves a Svelte SFC template via SSR.</p>
<p>Compiles the SFC with svelte/compiler (server mode + runes), bundles with rolldown, then wraps with svelte/server render().</p>
</div>
<div class="ox-api-entry__section ox-api-entry__section--signature">
<h4>Signature</h4>
<pre><code class="language-typescript">async function resolveSvelteTemplate(templatePath: string, root: string): Promise&lt;OgImageTemplateFn&gt;</code></pre>
</div>
<p class="ox-api-entry__source"><a class="ox-api-entry__source-link" href="https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/og-image/template-loader.ts#L154-L204" target="_blank" rel="noopener noreferrer">View source<span class="ox-api-entry__source-icon" aria-hidden="true"></span></a></p>
<div class="ox-api-entry__section ox-api-entry__section--params">
<h4>Parameters</h4>
<ul class="ox-api-entry__params">
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">templatePath</code>
    <code class="ox-api-entry__param-type">string</code>
  </div>
</li>
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">root</code>
    <code class="ox-api-entry__param-type">string</code>
  </div>
</li>
</ul>
</div>
<div class="ox-api-entry__section ox-api-entry__section--returns">
<h4>Returns</h4>
<div class="ox-api-entry__return">
  <code class="ox-api-entry__return-type">Promise&lt;<a href="./og-image-types.md#ogimagetemplatefn">OgImageTemplateFn</a>&gt;</code>
</div>
</div>
  </div>
</details>

<details id="resolvetemplate" class="ox-api-entry">
  <summary><span class="ox-api-entry__kind">fn</span><span class="ox-api-entry__summary-main"><code class="ox-api-entry__signature ox-api-entry__signature--highlighted language-typescript">resolveTemplate(options: ResolvedOgImageOptions, root: string): Promise&lt;OgImageTemplateFn&gt;</code><span class="ox-api-entry__description">Resolves the template function from options. Dispatches by file extension: - .v…</span><span class="ox-api-entry__meta"><span class="ox-api-badge">2 params</span><span class="ox-api-badge">returns Promise&lt;OgImageTemplateFn&gt;</span></span></span></summary>
  <div class="ox-api-entry__body">
<div class="ox-api-entry__prose">
<p>Resolves the template function from options.</p>
<p>Dispatches by file extension:</p>
<ul>
<li><code>.vue</code>  → Vue SFC (SSR via vue/server-renderer)</li>
<li><code>.svelte</code> → Svelte SFC (SSR via svelte/server)</li>
<li><code>.tsx</code>/<code>.jsx</code> → React Server Component (SSR via react-dom/server)</li>
<li>others → TypeScript template (direct function export)</li>
</ul>
</div>
<div class="ox-api-entry__section ox-api-entry__section--signature">
<h4>Signature</h4>
<pre><code class="language-typescript">export async function resolveTemplate(options: ResolvedOgImageOptions, root: string): Promise&lt;OgImageTemplateFn&gt;</code></pre>
</div>
<p class="ox-api-entry__source"><a class="ox-api-entry__source-link" href="https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/og-image/template-loader.ts#L17-L67" target="_blank" rel="noopener noreferrer">View source<span class="ox-api-entry__source-icon" aria-hidden="true"></span></a></p>
<div class="ox-api-entry__section ox-api-entry__section--params">
<h4>Parameters</h4>
<ul class="ox-api-entry__params">
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">options</code>
    <code class="ox-api-entry__param-type"><a href="./og-image-types.md#resolvedogimageoptions">ResolvedOgImageOptions</a></code>
  </div>
</li>
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">root</code>
    <code class="ox-api-entry__param-type">string</code>
  </div>
</li>
</ul>
</div>
<div class="ox-api-entry__section ox-api-entry__section--returns">
<h4>Returns</h4>
<div class="ox-api-entry__return">
  <code class="ox-api-entry__return-type">Promise&lt;<a href="./og-image-types.md#ogimagetemplatefn">OgImageTemplateFn</a>&gt;</code>
</div>
</div>
  </div>
</details>

<details id="resolvetstemplate" class="ox-api-entry">
  <summary><span class="ox-api-entry__kind">fn</span><span class="ox-api-entry__summary-main"><code class="ox-api-entry__signature ox-api-entry__signature--highlighted language-typescript">resolveTsTemplate(templatePath: string, options: ResolvedOgImageOptions, root: string): Promise&lt;OgImageTemplateFn&gt;</code><span class="ox-api-entry__description">Resolves a plain TypeScript template (existing behavior).</span><span class="ox-api-entry__meta"><span class="ox-api-badge">3 params</span><span class="ox-api-badge">returns Promise&lt;OgImageTemplateFn&gt;</span></span></span></summary>
  <div class="ox-api-entry__body">
<div class="ox-api-entry__prose">
<p>Resolves a plain TypeScript template (existing behavior).</p>
</div>
<div class="ox-api-entry__section ox-api-entry__section--signature">
<h4>Signature</h4>
<pre><code class="language-typescript">async function resolveTsTemplate(templatePath: string, options: ResolvedOgImageOptions, root: string): Promise&lt;OgImageTemplateFn&gt;</code></pre>
</div>
<p class="ox-api-entry__source"><a class="ox-api-entry__source-link" href="https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/og-image/template-loader.ts#L117-L146" target="_blank" rel="noopener noreferrer">View source<span class="ox-api-entry__source-icon" aria-hidden="true"></span></a></p>
<div class="ox-api-entry__section ox-api-entry__section--params">
<h4>Parameters</h4>
<ul class="ox-api-entry__params">
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">templatePath</code>
    <code class="ox-api-entry__param-type">string</code>
  </div>
</li>
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">options</code>
    <code class="ox-api-entry__param-type"><a href="./og-image-types.md#resolvedogimageoptions">ResolvedOgImageOptions</a></code>
  </div>
</li>
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">root</code>
    <code class="ox-api-entry__param-type">string</code>
  </div>
</li>
</ul>
</div>
<div class="ox-api-entry__section ox-api-entry__section--returns">
<h4>Returns</h4>
<div class="ox-api-entry__return">
  <code class="ox-api-entry__return-type">Promise&lt;<a href="./og-image-types.md#ogimagetemplatefn">OgImageTemplateFn</a>&gt;</code>
</div>
</div>
  </div>
</details>

<details id="tstemplatebundleoptions" class="ox-api-entry">
  <summary><span class="ox-api-entry__kind">fn</span><span class="ox-api-entry__summary-main"><code class="ox-api-entry__signature ox-api-entry__signature--highlighted language-typescript">tsTemplateBundleOptions(templatePath: string)</code><span class="ox-api-entry__description">Rolldown input options for a .ts template bundle. A .ts template is the framewo…</span><span class="ox-api-entry__meta"><span class="ox-api-badge">1 param</span></span></span></summary>
  <div class="ox-api-entry__body">
<div class="ox-api-entry__prose">
<p>Rolldown input options for a <code>.ts</code> template bundle.</p>
<p>A <code>.ts</code> template is the framework-less kind, so it has no single runtime to externalize the way the <code>.vue</code>, <code>.svelte</code> and <code>.tsx</code> paths do — anything from <code>node_modules</code> 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.</p>
</div>
<div class="ox-api-entry__section ox-api-entry__section--signature">
<h4>Signature</h4>
<pre><code class="language-typescript">export function tsTemplateBundleOptions(templatePath: string)</code></pre>
</div>
<p class="ox-api-entry__source"><a class="ox-api-entry__source-link" href="https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/og-image/template-loader.ts#L106-L112" target="_blank" rel="noopener noreferrer">View source<span class="ox-api-entry__source-icon" aria-hidden="true"></span></a></p>
<div class="ox-api-entry__section ox-api-entry__section--params">
<h4>Parameters</h4>
<ul class="ox-api-entry__params">
<li class="ox-api-entry__param">
  <div class="ox-api-entry__param-heading">
    <code class="ox-api-entry__param-name">templatePath</code>
    <code class="ox-api-entry__param-type">string</code>
  </div>
</li>
</ul>
</div>
  </div>
</details>
