A Vite plugin built specifically for Halo theme development.
It precompiles templates before Vite processes HTML, adds lightweight template reuse features (include, slot, props) for Halo themes, and automatically treats HTML files in src as multi-page entries output to templates.
Halo themes often need reusable page fragments and layout composition. This plugin fills that gap during precompilation, reducing template duplication and improving maintainability.
Main capabilities:
- Template reuse features: supports
include,slot,props, and related semantics. - Automatically scans the
srcdirectory, uses all HTML files as Vite build entries, and handles static asset imports.
pnpm add -D @halo-dev/vite-plugin-halo-themeEnable the plugin in vite.config.ts:
import { defineConfig } from "vite";
import { haloThemePlugin } from "@halo-dev/vite-plugin-halo-theme";
export default defineConfig({
plugins: [haloThemePlugin()],
});See the runnable example project in example.
cd example
pnpm install
pnpm buildThis plugin is Halo-specific and uses the following defaults:
- Page source directory:
src - Partials directory:
src/partials - Static assets directory:
public - Output directory:
templates - Output assets directory:
templates/assets
Example structure:
.
├── public
│ └── ...
├── src
│ ├── js
│ │ ├── index.js
│ │ └── post.js
│ ├── css
│ │ └── index.css
│ ├── index.html # page entry
│ ├── post.html # page entry
│ └── partials # template partials directory (convention)
│ ├── layout.html # partial template
│ └── card.html # partial template
├── theme.yaml
└── templates # output directory for templates and assets
The plugin scans all .html files under src and skips src/partials.
Mapping examples:
src/index.html->templates/index.htmlsrc/post.html->templates/post.html
Note: The syntax in this section (
include,slot,props) is precompiled only during the Vite build phase. It is not native Thymeleaf syntax.
Keep the two phases separate: Vite compile time (frontend build) vs Thymeleaf render time (backend runtime).
<include src="layout.html">
<main>...</main>
</include>Usage:
<include src="card.html" title="Hello"></include>In partial:
<h2>{{title}}</h2>In partial:
<slot />In partial:
<slot name="head" />Usage:
<include src="layout.html">
<template name="head">
<title>Page Title</title>
</template>
<main>...</main>
</include>./foo.html/../foo.html: relative to current file/foo.html: relative tosrcfoo.html: resolvessrc/partials/foo.htmlfirstpartials/foo.html: resolves assrc/partials/foo.html
pnpm install
pnpm test
pnpm build
pnpm lint
pnpm fmt- The current parser is intentionally lightweight and focused on plugin syntax needs, not full HTML5 specification parsing.
{{prop}}is string-level interpolation and does not evaluate expressions.- This plugin is purpose-built for Halo themes, not a general template engine for all site stacks.