A Vite plugin that renders Twig templates into static HTML files during the build process.
Used in HalfDeal WebLayout Starter at vite-twig-ssg branch.
- Renders Twig templates (
.twig,.twig.html) into static HTML during Vite build. - Supports nested directory structures.
- Customizable input/output directories and extensions.
- Uses Vite's global config for root and output directories (overridable).
- Easy configuration and integration.
npm install vite-plugin-twig-builder// vite.config.js
import { defineConfig } from 'vite'
import twigBuilder from 'vite-plugin-twig-builder'
export default defineConfig({
plugins: [
twigBuilder({
// Optional: override defaults (see below for config options)
root: './src',
dir: './src/pages',
outDir: './dist',
extensions: ['.twig', '.twig.html'],
ignoredPaths: []
})
]
});You can pass an optional configuration object to twigBuilder():
| Option | Type | Default | Description |
|---|---|---|---|
dir |
string |
./src/pages |
Source directory for twig templates |
outDir |
string |
./dist |
Output directory for generated HTML |
root |
string |
./src |
Twig root directory (for layouts/partials) |
extensions |
string[] |
['.twig', '.twig.html'] |
File extensions to process |
Note: If you do not specify these options, the plugin will use values from Vite's own config (
root,build.outDir) where appropriate.
This project is licensed under the Apache License 2.0. See LICENSE for details.
Vasilev Aleksandr
Github | Telegram | Telegram Channel | VK | VK Group