@lediv/vite-plugin
v0.2.1
Published
Vite plugin for building Lediv projects
Maintainers
Readme
@lediv/vite-plugin
Vite plugin for building Lediv projects. Serves and builds multi-page HTML applications with component resolution, template evaluation, font injection, and mount script chunking.
Install
npm install @lediv/vite-pluginRequires vite as a peer dependency.
Usage
import { defineConfig } from 'vite';
import lediv from '@lediv/vite-plugin';
export default defineConfig({
plugins: [lediv()],
});The plugin expects a pages/ directory and an optional components/ directory at the Vite root.
Options
lediv({
preloadFonts: true,
});| Option | Type | Default | Description |
| -------------- | --------- | ------- | ---------------------------------------------------------------- |
| preloadFonts | boolean | false | Emit <link rel="preload"> tags for fonts detected in each page |
Dev server
The plugin registers a middleware that:
- Responds to
/fonts/:id/latin-wght-normal.woff2requests directly from the bundled font assets. - Matches request URLs to HTML files under
pages/and serves the built result throughtransformIndexHtml. - Triggers a full page reload on HMR changes inside
pages/orcomponents/.
Build
On build the plugin:
- Collects all
.htmlfiles underpages/recursively. - Resolves component trees and evaluates template logic for each page.
- Emits inline mount scripts as separate JS chunks (one per component instance).
- Copies required WOFF2 font files to
dist/fonts/:id/. - Emits final HTML files as build assets, verbatim. Nothing is minified: the output is the HTML you authored, and compression on the wire (gzip/brotli) recovers almost all of what minifying would have saved.
- Copies a
_redirectsfile from the Vite root into the output, unchanged, if there is one.
Redirects
A _redirects file at the Vite root is copied to the root of the build output as-is, whether or not the project has any pages. That is the file Netlify and Cloudflare Pages read to serve redirects, and it is the same file Lediv reads when it publishes the project, so the rules a project was written with keep working after you export it and deploy it yourself.
The plugin does not parse or validate the file. The rule syntax is documented at https://lediv.com/docs/redirects.
Build utilities entry point
import { buildPage, buildPageFromSource } from '@lediv/vite-plugin/build';buildPage is the low-level page builder used by the plugin. It accepts a page name and options, reads the source HTML, resolves components, injects font CSS, and returns { html, usedFonts, mountScripts }.
import type { BuildPageOptions, BuildPageResult } from '@lediv/vite-plugin/build';License
MIT
