@zerolith/vite
The Vite plugin for zerolith, for projects that use Vite. A zerolith project does not need Vite: zerolith dev and zerolith build from @zerolith/cli serve and bundle it on their own, with the same passes this plugin runs. zerolith also runs under Vite with no plugin: the packages are plain ES modules, and Vite's default development condition selects the diagnostic build and the inspector in development. The plugin adds what a build step makes possible.
// vite.config.ts
import { defineConfig } from "vite";
import { zerolith } from "@zerolith/vite";
export default defineConfig({
plugins: [zerolith()]
});
- JSX.
.jsxand.tsxfiles are lowered to thehtmlcalls they stand for, so nothing from JSX reaches the browser.jsx: falseleaves them to Vite. - Scoped stylesheets.
import card from "./card.css?scoped"gives the styles acssliteral gives, from the file as Vite's CSS pipeline processes it, and an edit to the file replaces its rules in place. - Hot replacement that understands components. In development, exported components become stable proxies to their latest version,
renderandhydrateroots render again after an edit, and named signals keep their values.hot: falseleaves it out, as a test runner wants: Vitest takeszerolith({ hot: false })for JSX and?scopedstylesheets. - Warnings at transform time for a frozen
${signal.get()}read in a template and for images, buttons, and frames without an accessible name, each with a diagnostic code.lint: falseturns them off. - Templates prepared at build time.
vite buildscans everyhtmlliteral ahead of time, so the browser binds templates without scanning them and the scanner leaves the bundle, and a template with no bindings is created once at module scope. A module that useshtmlother than as a template tag, or re-exports it, fails the build at that line.prepare: falsekeeps the scanner. - Build checks. A client build fails when a view loaded with the router's
lazy(), or a locale of a compiled message index, is also imported statically, which would merge it into the importing chunk. A build in production mode also fails when the development build of the core reached the output.
The guide is on the docs site.
Status: alpha. Install with npm install --save-dev @zerolith/vite@alpha, at the version of zerolith the project uses: the two share the zerolith/internal entry, and the plugin stops with package_version_mismatch on any other version. The API may change before 1.0.
Documentation
- The Vite guide explains it with examples that run as tests.
- The reference lists every export, generated from the source.
- New to zerolith? The tutorial builds an app step by step, and the playground runs code in the browser.
License
Apache-2.0. See LICENSE.