Skip to content

transformTemplate

transformTemplate(options?): object

Defined in: index.ts:34

Rollup/Vite/Rolldown plugin that transforms text files into default-exported string literals so they can be imported directly in code.

Two categories of files are transformed:

  1. .yml and .md files — always, regardless of location (except under node_modules).
  2. Any non-JSON file whose resolved path contains a string listed in dirs.

JSON files in dirs are intentionally excluded: bundlers handle .json imports natively as typed objects, which is more useful than a raw string.

TransformTemplateOptions = {}

object

name: string = "rollup-plugin-transform-template"

transform(_code, id): { code: string; map: null; } | null

string

string

{ code: string; map: null; } | null

// vite.config.ts / vitest.config.ts / tsdown.config.ts
import { transformTemplate } from "@theholocron/rollup-plugin-transform-template";
plugins: [transformTemplate({ dirs: ["/src/commands/setup/templates/"] })]