Vite Plugin
vite-plugin-nudo integrates Nudo's type inference into your Vite build. File selection follows nudo.analysis.mode (same gate as LSP/CLI via shouldAnalyzeFile); the shipped default is "exports" (files with @nudo:*, export, or a sidecar are analyzed).
Installation
npm install vite-plugin-nudo --save-dev
pnpm add -D vite-plugin-nudo
Configuration
Add the plugin to your vite.config.ts:
import { defineConfig } from "vite";
import nudo from "vite-plugin-nudo";
export default defineConfig({
plugins: [
nudo(),
// ... other plugins
],
});
Options
| Option | Type | Default | Description |
|---|---|---|---|
include | string[] | ["**/*.js", "**/*.mjs", "**/*.ts"] | Glob patterns for files to analyze (aligned with isNudoTargetPath) |
exclude | string[] | ["**/node_modules/**", "**/*.d.ts"] | Glob patterns for files to skip |
failOnError | boolean | false | When true, Nudo type errors become build errors |
Example with Options
import { defineConfig } from "vite";
import nudo from "vite-plugin-nudo";
export default defineConfig({
plugins: [
nudo({
include: ["**/*.js", "**/*.mjs"],
exclude: ["**/node_modules/**", "**/dist/**"],
failOnError: true,
}),
],
});
Glob patterns support any file extension (**/*.js, **/*.mjs, **/*.ts, …), directory-segment patterns (**/node_modules/**, **/dist/**), and wildcard-free patterns, which are matched as literal substrings of the file path.
Behavior
- File matching: The plugin processes files that match
includeand do not matchexclude;excludealways wins. The defaultincludeof["**/*.js", "**/*.mjs", "**/*.ts"]matchesisNudoTargetPath(.cjs/.cts/.mts/.tsxare not analysis targets). - Analysis gate: After globs, files pass
shouldAnalyzeFile(package.json#nudo.analysis.mode). Shipped default is"exports"— files with@nudo:*,export, or a sidecar are analyzed. Set"all"for every target path, or"directives"for the conservative gate. - Analysis: Matching files use
analyzeFileAsyncfrom@nudojs/serviceto run type inference. - Refinement gate: Matching files also pass through the Abs refinement gate (
checkSourcefrom@nudojs/core):nudo:constraint-violated,nudo:assign-mismatch, andnudo:arg-structureissues are merged into the same diagnostics pipeline and reported alongside evaluator diagnostics. - Caching: Analysis results are cached per file. The cache is cleared at
buildStart. - Diagnostics: Errors and warnings from analysis are emitted as Vite warnings (or errors when
failOnErroristrue). At build end, a summary is logged:[nudo] Analysis complete: X error(s), Y warning(s).
failOnError
failOnError: false(default): Type errors from Nudo are reported as Vite warnings. The build continues.failOnError: true: Nudo type errors are reported as build errors, causing the build to fail.
Use failOnError: true when you want Nudo to enforce type correctness as part of your CI or production build.