@pithyjs/vite-plugin
v0.2.0-beta.29
Published
Vite plugins for the PithyJS framework. Provides `.pithy` file compilation, `html\`…\`` template transformation, file-based routing, build optimization, design system CSS tree-shaking, SSR dev server, and icon sprite generation.
Readme
@pithyjs/vite-plugin
Vite plugins for the PithyJS framework. Provides .pithy file compilation, html\…`` template transformation, file-based routing, build optimization, design system CSS tree-shaking, SSR dev server, and icon sprite generation.
Installation
npm install @pithyjs/vite-pluginpnpm add @pithyjs/vite-pluginyarn add @pithyjs/vite-pluginPlugins
pithyPlugin
Transforms .pithy single-file components into compiled TypeScript modules with HMR support.
htmlTransformPlugin
Babel-based transform for html\…`tagged template literals. Compiles templates ahead of time (AOT) invite devandvite buildalike, so dev renders what a build ships and no HTML is parsed at runtime.aot: falseopts out and renders every template through the runtime compiler (JIT) until JIT is retired;strictAot: truemakes a template that falls back to JIT an error. The dev serverpithy-ssg` renders static pages through stays on JIT (static export moves to AOT later), so until then an exported page can differ from dev where the two compilers do, such as content for a slot the component does not render (BUG-130).
pithyRouter
File-based routing plugin. Scans a routes directory and generates a typed route manifest as a virtual module.
pithyBuild
Build optimization plugin providing chunk naming strategies, vendor splitting, and route-based code splitting.
designSystemPlugin
CSS tree-shaking plugin that extracts used utility classes and generates only the CSS needed.
It additionally prepends a static color palette to the virtual:pithy-design-system
module, so SSR/SSG output — which never runs the runtime ThemeManager — still
resolves every var(--color-*). The palette is intentionally not JIT-gated,
because UI Kit component SCSS references color tokens outside of any u-*
utility class. Cost: a fixed ~36.6 KB raw / ~3.7 KB gzip.
Configure it with the colors option, which must mirror the app's
pithy.config.ts designSystem.colors — if the two diverge, hydration rewrites
the tokens and the page flashes:
designSystemPlugin({
colors: { seed: { primary: '#3b82f6' }, mode: 'light' },
});The palette values are produced by @pithyjs/design-system/palette, which shares
its formatter with the runtime writer, so the pre-painted CSS and the values
hydration writes are identical by construction.
⚠️ Do not import
@pithyjs/design-system/colors/stylesin an app that uses this plugin. Both define the same--color-*tokens on overlapping selectors, so whichever comes last in source order wins. If that is the SCSS, your page paints the default theme and your configuredseedis ignored. Pick one source of truth.
pithySSR
SSR dev server plugin with auto-mode (pithy.config.ts) and legacy mode (entry-server.ts).
pithyIcons
SVG icon sprite generation plugin with optimization, HMR, and virtual module output.
Two virtual modules are emitted:
virtual:pithy-icons—SPRITE_URL,ICON_NAMES,ICON_METAfor runtime registration viaregisterIconSprite().virtual:pithy-icons/sprite—SPRITE_CONTENT, the sprite text itself. Used bypithy-ssgto inline the<symbol>s a page actually uses instead of referencing a sprite file the output never ships. Kept as a separate module so the sheet never rides along in a client bundle that only wants the URL. (Studio's exporter solves the same problem, but it runs in a browser and fetches the sprite over HTTP from the registeredSPRITE_URLrather than going through this module.)
API Reference
.pithy Plugin
| API | Signature | Stability | Description |
| --- | --- | --- | --- |
| pithyPlugin | () => Plugin | stable | - |
HTML Transform Plugin
| API | Signature | Stability | Description |
| --- | --- | --- | --- |
| HtmlTransformPluginOptions | interface HtmlTransformPluginOptions | stable | - |
| htmlTransformPlugin | (options?: HtmlTransformPluginOptions) => PluginOption | stable | - |
Build Plugin
| API | Signature | Stability | Description |
| --- | --- | --- | --- |
| pithyBuild | (options?: PithyBuildOptions) => Plugin | stable | - |
Router Plugin
| API | Signature | Stability | Description |
| --- | --- | --- | --- |
| pithyRouter | (options?: PithyRouterPluginOptions) => Plugin | experimental | - |
Design System Plugin
| API | Signature | Stability | Description |
| --- | --- | --- | --- |
| designSystemPlugin | (options?: DesignSystemPluginOptions) => Plugin | experimental | - |
Icons Plugin
| API | Signature | Stability | Description |
| --- | --- | --- | --- |
| pithyIcons | (options?: PithyIconsOptions) => Plugin | stable | - |
SSR Plugin
| API | Signature | Stability | Description |
| --- | --- | --- | --- |
| pithySSR | (options?: PithySSRPluginOptions) => Plugin | experimental | - |
Examples
import { pithyPlugin } from '@pithyjs/vite-plugin';
export default defineConfig({
plugins: [pithyPlugin()],
});import { htmlTransformPlugin } from '@pithyjs/vite-plugin';
export default defineConfig({
plugins: [htmlTransformPlugin({ strictAot: true })],
});// vite.config.ts
import { pithyBuild } from '@pithyjs/vite-plugin';
export default defineConfig({
plugins: [
pithyBuild(),
],
});import { pithyRouter } from '@pithyjs/vite-plugin';
export default defineConfig({
plugins: [pithyRouter({ routesDir: 'src/routes' })],
});// design-system.config.ts — type import only, so bare Node can load it
import type { DesignSystemConfig } from '@pithyjs/design-system/palette';
export const designSystem: DesignSystemConfig = {
shadows: { preset: 'elevated' },
};// vite.config.ts
import { designSystemPlugin } from '@pithyjs/vite-plugin';
import { designSystem } from './design-system.config';
export default defineConfig({
plugins: [
designSystemPlugin({
// Same object pithy.config.ts uses — no mirroring, no drift
designSystem,
safelist: ['u-bg-success', /^u-text-/],
debug: true,
})
]
});// vite.config.ts
import { pithyIcons } from '@pithyjs/vite-plugin';
export default defineConfig({
plugins: [
pithyIcons({ dir: 'src/icons' })
]
});// main.ts — register icons at app startup
import { SPRITE_URL, ICON_NAMES, ICON_META } from "virtual:pithy-icons";
import { registerIconSprite } from "@pithyjs/ui-kit/icons";
registerIconSprite(SPRITE_URL, ICON_NAMES, ICON_META);Testing
| Feature | Unit | Integration | E2E | Status | | --- | --- | --- | --- | --- | | pithyPlugin | - | - | - | Missing unit, integration |
| Feature | Unit | Integration | E2E | Status | | --- | --- | --- | --- | --- | | HtmlTransformPluginOptions | - | - | - | Missing unit, integration | | htmlTransformPlugin | ✓ | - | - | Missing integration |
| Feature | Unit | Integration | E2E | Status | | --- | --- | --- | --- | --- | | pithyBuild | - | - | - | Missing integration |
| Feature | Unit | Integration | E2E | Status | | --- | --- | --- | --- | --- | | pithyRouter | ✓ | - | - | Missing integration |
| Feature | Unit | Integration | E2E | Status | | --- | --- | --- | --- | --- | | designSystemPlugin | - | ✓ | - | Complete |
| Feature | Unit | Integration | E2E | Status | | --- | --- | --- | --- | --- | | pithyIcons | ✓ | - | - | Complete |
| Feature | Unit | Integration | E2E | Status | | --- | --- | --- | --- | --- | | pithySSR | ✓ | - | - | Complete |
License
MIT
