@lediv/vite-plugin
v0.1.0
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 |
| minifyInline | boolean | true | Minify inline <style> and <script> content in emitted pages (build only) |
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).
- Minifies inline
<style>and<script>content unlessminifyInlineisfalse. Untyped,type="module", andtype="text/javascript"scripts are minified as JavaScript;type="application/ld+json"scripts are compacted through a JSON round-trip and invalid JSON fails the build; scripts with any othertypeor with asrcattribute stay verbatim. Markup outside these blocks is never touched, and the dev server always serves unminified output. - Copies required WOFF2 font files to
dist/fonts/:id/. - Emits final HTML files as build assets.
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
