@zerolith/vite
Import from @zerolith/vite. Generated from the source; every signature below is what the published types declare.
Functions
lowerJsx
function lowerJsx(code: string, id: string, parse: ModuleParser): JsxOutput | nullLowers every JSX expression in a module to html calls and imports
html under a private name. Returns null when the module has no JSX.
The parser must be set up for JSX, tsx for a .tsx file.
Source: packages/vite/src/jsx.ts:406
lintModule
function lintModule(code: string, id: string, parse: ModuleParser): Finding[]Checks every html template in a module. Returns the findings in source
order; a module without templates, or one that does not parse, yields
none, since the parser's own errors come first.
Source: packages/vite/src/lint.ts:132
position
function position(code: string, offset: number): { line: number; column: number }The line and column, 1-based, of an offset in a module.
Source: packages/vite/src/lint.ts:170
prepareModule
function prepareModule(code: string, id: string, parse: ModuleParser, scan: TemplateScanner): PrepareOutput | nullPrepares one module. Returns null when the module imports no html from
zerolith, and throws a PrepareError when html is declared or used
other than as a template tag, since the bundle will carry no scanner.
Source: packages/vite/src/prepare.ts:147
splitImports
function splitImports(code: string, id: string, parse: ModuleParser): SplitImport[]The dynamic imports of a module that are meant to stay chunks of their
own, in source order: every import() with a string specifier inside the
loader passed to the router's lazy(), and every one in a compiled
message index. Any other module yields none.
Source: packages/vite/src/split.ts:101
transformModule
function transformModule(code: string, id: string, parse: ModuleParser): TransformOutput | nullRewrites one module for hot replacement. Exported functions whose names
start with a capital letter become proxies registered under the module's
import.meta.hot.data; calls to render and hydrate imported from
zerolith are routed through the runtime with the rendered expression
wrapped in a factory; and a module that needed either change accepts its
own updates. A module that needs neither comes back as null, untouched.
Source: packages/vite/src/transform.ts:174
zerolith
function zerolith(options?: ZerolithPluginOptions): Plugin[]Creates the plugins. Ahead of every other transform, JSX in .jsx and
.tsx files is lowered to the html calls it stands for. A stylesheet
imported with ?scoped becomes a module that hands its rules, as Vite's
?inline import processes them, to zerolith's styleFile, which scopes
them as it scopes a css literal's; the module accepts its own update,
so an edited stylesheet replaces its rules in place. In
development each module is rewritten so exported functions with
capitalized names become stable proxies, render and hydrate calls
are recorded with the expression they rendered, and a changed module
accepts its own update: named signals are saved before the module is
replaced, every root renders again, and the saved values flow back into
signals created with the same names. The zerolith packages are kept out
of dependency pre-bundling. In vite build every html literal is
scanned ahead of time and the scanner leaves the bundle. A client build
fails when a view loaded with the router's lazy(), or a locale module
of a compiled message index, is also imported statically, which would
put it in the importing chunk, and a build in production mode fails if
a module of the development build of the core reached the output, which
means the production export condition did not apply. Creating the
plugin fails with package_version_mismatch when the installed zerolith
is not the version the plugin was released with.
Source: packages/vite/src/index.ts:153
Classes
JsxError
class JsxError extends ErrorThrown for JSX the lowering refuses, with the offset in the module.
constructor(message: string, offset: number): Creates the error withmessageafter azerolith:prefix and the offset of the refused node.readonly offset: number: Offset in the module of the JSX node the lowering refused, whichpositionturns into a line and column.
Source: packages/vite/src/jsx.ts:98
PrepareError
class PrepareError extends ErrorThrown for a module the pass refuses, with the offset in the module.
constructor(message: string, offset: number): Creates the error withmessageafter azerolith:prefix and the offset of the refused code.readonly offset: number: Offset in the module of the statement, expression, or template the pass refused; the plugin turns it into the error's line and column.
Source: packages/vite/src/prepare.ts:85
Interfaces
AstNode
interface AstNodeWhat every ESTree node carries.
type: string: The ESTree node type, such asCallExpression;walktreats any object with a stringtypeas a node.start: number: Offset of the node's first character, as an index into the parsed code.end: number: Offset just past the node's last character, socode.slice(start, end)is the node's source text.
Source: packages/vite/src/ast.ts:7
Edit
interface EditOne replacement of a source range; a zero-length range inserts.
start: number: Offset where the replaced range starts, as an index into the code the edit applies to.end: number: Offset just past the last character replaced; equal tostartfor an insertion.text: string: The text written in place of the range; empty to delete it.
Source: packages/vite/src/ast.ts:18
IdentityMap
interface IdentityMapA line-preserving source map: every output line maps to the same input line.
version: 3: The version of the source map format, always the integer 3.sources: string[]: The original sources the mappings refer to by index; the identity map lists only the module's id.names: string[]: The symbol names the mappings refer to by index; empty, since no segment of an identity map names a symbol.mappings: string: The encoded mapping data: one group of Base64 VLQ segments per generated line, groups separated by;and segments by,; the identity map writes one segment per line.
Source: packages/vite/src/ast.ts:29
JsxOutput
interface JsxOutputThe result of lowering one module.
code: string: The module text with each JSX expression replaced, on the same lines, by thehtmlcall it stands for, and thehtmlimport added at the start of the first line.map: IdentityMap: The identity source map from each lowered line to the same line of the original file.
Source: packages/vite/src/jsx.ts:12
Finding
interface FindingOne finding.
readonly code: LintCode: The check that produced the finding, also the diagnostic code whose documentation page the plugin's warning links.readonly message: string: What is wrong and how to fix it; the plugin's warning prints it between the code and the code's documentation URL.readonly offset: number: Offset of the finding in the module.
Source: packages/vite/src/lint.ts:13
PrepareOutput
interface PrepareOutputThe result of preparing one module.
code: string: The module text, line for line: eachhtmlliteral becomes a call of its tag on a template registered before the first statement that is not an import, and one without values becomes a view made once there.map: IdentityMap: The identity source map from each prepared line to the same line of the original module.
Source: packages/vite/src/prepare.ts:11
ScannedPart
interface ScannedPartOne scanned part, as the core's scan reports it.
readonly kind: number: How the part binds, numbered as the core's part constants are:0child,1attribute,2boolean,3property,4event,5ref.readonly name: string: The bound attribute, property, or event name without its.,?, or@prefix; empty for a child part.readonly strings: readonly string[]: The static text around an attribute value's expressions, one entry longer than their count; empty for a child part.
Source: packages/vite/src/prepare.ts:20
SplitImport
interface SplitImportA dynamic import that is meant to stay a chunk of its own.
readonly specifier: string: The specifier as written in theimport().readonly kind: "route" | "locale":routefor a view declared withlazy(),localefor a module of a compiled message index.readonly offset: number: Offset of theimport()in the module.
Source: packages/vite/src/split.ts:16
ParsedModule
interface ParsedModuleA parsed module: the program body and any syntax errors the parser reported.
program: { body: readonly AstNode[] }: The module's ESTreeProgramnode; the passes read its top-level statements frombodyand walk the nodes beneath them.errors: readonly unknown[]: The syntax errors the parser reported; each pass leaves a module with errors untouched, so the parser's own errors come first.
Source: packages/vite/src/transform.ts:19
TransformOutput
interface TransformOutputThe rewritten module and its line-preserving source map.
code: string: The rewritten module: its own lines, rewritten in place, followed by any re-exports of renamed components and the footer that accepts hot updates.map: IdentityMap: The identity source map; each line appended after the module's own lines maps to its last line.
Source: packages/vite/src/transform.ts:31
ZerolithPluginOptions
interface ZerolithPluginOptionsOptions for zerolith().
include?: RegExp: Module ids to rewrite, tested with path separators normalized to/. Defaults to JavaScript and TypeScript modules.exclude?: RegExp: Module ids to leave alone even whenincludematches. Defaults to anything undernode_modules.jsx?: boolean: Lowers JSX in.jsxand.tsxfiles tohtmlcalls. Defaults to true.hot?: boolean: Rewrites modules in development so an edited component is replaced in place. Defaults to true, and to false under Vitest, where nothing is edited in place.lint?: boolean: Warns in the terminal about a.get()read bound in a template and about static accessibility defects. Defaults to true.prepare?: boolean: Invite build, scans everyhtmlliteral ahead of time and drops the scanner from the bundle. Defaults to true.
Source: packages/vite/src/index.ts:31
Types
LintCode
type LintCode = "template_frozen_read" | "image_without_alt" | "button_without_name" | "frame_without_title"The checks lintModule runs.
Source: packages/vite/src/lint.ts:10
TemplateScanner
type TemplateScanner = (strings: readonly string[]) => { markup: string; parts: readonly ScannedPart[] }Scans a template's cooked strings: the core's scan, passed in so the pass has no import of its own.
Source: packages/vite/src/prepare.ts:31
ModuleParser
type ModuleParser = (filename: string, code: string) => ParsedModuleParses JavaScript module text; the plugin passes Vite's parseSync.
Source: packages/vite/src/transform.ts:28
Constants
PREPARED_BINDING
const PREPARED_BINDING: stringThe binding the lowered code imports prepared under, chosen not to clash with user code.
Source: packages/vite/src/prepare.ts:34
TEMPLATE_BINDING
const TEMPLATE_BINDING: stringThe prefix of the hoisted template bindings, numbered per module.
Source: packages/vite/src/prepare.ts:36
VIEW_BINDING
const VIEW_BINDING: stringThe prefix of the module-scope views of templates with no bindings, numbered like their templates.
Source: packages/vite/src/prepare.ts:38
MESSAGES_HEADER
const MESSAGES_HEADER: stringThe start of every module zerolith-i18n writes.
Source: packages/vite/src/split.ts:11