Skip to content

Rollup Plugin Transform Template

@theholocron/rollup-plugin-transform-template turns template files into default-exported strings, so a build or a test run can import them directly. It works with tsdown, Vite, Vitest and Rolldown.

Terminal window
pnpm add -D @theholocron/rollup-plugin-transform-template
// tsdown.config.ts / vite.config.ts / vitest.config.ts
import { transformTemplate } from "@theholocron/rollup-plugin-transform-template";
export default defineConfig({
plugins: [transformTemplate({ dirs: ["/src/templates/"] })],
});

Then import a template file like any module; the default export is its text:

import labelerBody from "./labeler.yml";
File type Condition Result
.yml, .md Always Default-exported string
Any non-JSON extension Path contains a string from dirs Default-exported string
.json Even inside dirs Not transformed: bundlers import JSON natively
.ts, .tsx Even inside dirs Not transformed: source files, not templates

Add @theholocron/rollup-plugin-transform-template/client to types in your tsconfig.json so *.yml and *.md imports are typed as strings.

The full API reference is generated from the package’s TSDoc comments.