Solid.js integration plugin for Vite 3/4/5/6 with HMR, TypeScript support, and minimal configuration
npx @tessl/cli install tessl/npm-vite-plugin-solid@2.11.0Vite Plugin Solid is the official Vite integration plugin for Solid.js that provides seamless development experience with Hot Module Replacement (HMR), TypeScript support, and zero configuration setup. It transforms JSX/TSX files using Babel with Solid-specific presets and handles development dependencies for optimal performance.
npm install -D vite-plugin-solidimport solidPlugin from "vite-plugin-solid";
import type { Options, ExtensionOptions } from "vite-plugin-solid";For CommonJS:
const solidPlugin = require("vite-plugin-solid");// vite.config.ts
import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";
export default defineConfig({
plugins: [solidPlugin()],
});Vite Plugin Solid is built around several key components:
babel-preset-solid for JSX transformation and solid-refresh for HMR.jsx, .tsx, and custom extensions with TypeScript support detectionCreates a Vite plugin instance for Solid.js integration with optional configuration.
/**
* Creates a Vite plugin for Solid.js integration
* @param options - Optional configuration options
* @returns Vite Plugin object
*/
function solidPlugin(options?: Partial<Options>): Plugin;Usage Example:
// Basic usage
export default defineConfig({
plugins: [solidPlugin()],
});
// With custom options
export default defineConfig({
plugins: [
solidPlugin({
dev: true,
hot: true,
ssr: false,
include: ["src/**/*.{js,jsx,ts,tsx}"],
extensions: ["mdx"],
solid: {
generate: "dom",
hydratable: false,
},
}),
],
});Named type exports for TypeScript usage.
export interface ExtensionOptions {
/** Whether extension should be processed with TypeScript */
typescript?: boolean;
}
export interface Options {
/** Files to include (picomatch pattern) */
include?: FilterPattern;
/** Files to exclude (picomatch pattern) */
exclude?: FilterPattern;
/** Inject solid-js/dev in development mode (default: true) */
dev?: boolean;
/** Force SSR code generation (default: false) */
ssr?: boolean;
/** Inject HMR runtime in dev mode (default: true) */
hot?: boolean;
/** Custom file extensions to process (default: undefined) */
extensions?: (string | [string, ExtensionOptions])[];
/** Additional babel transform options (default: {}) */
babel?:
| babel.TransformOptions
| ((source: string, id: string, ssr: boolean) => babel.TransformOptions)
| ((source: string, id: string, ssr: boolean) => Promise<babel.TransformOptions>);
/** Solid-specific JSX compilation options (default: {}) */
solid?: {
/** Remove unnecessary closing tags from templates (default: false) */
omitNestedClosingTags?: boolean;
/** Remove last closing tag from templates (default: true) */
omitLastClosingTag?: boolean;
/** Remove unnecessary quotes from templates (default: true) */
omitQuotes?: boolean;
/** Runtime module name (default: "solid-js/web") */
moduleName?: string;
/** Output mode: "dom" | "ssr" | "universal" (default: "dom") */
generate?: "ssr" | "dom" | "universal";
/** Include hydratable markers (default: false) */
hydratable?: boolean;
/** Enable automatic event delegation on camelCase (default: true) */
delegateEvents?: boolean;
/** Smart conditional detection for boolean expressions and ternaries (default: true) */
wrapConditionals?: boolean;
/** Set current render context on Custom Elements and slots (default: true) */
contextToCustomElements?: boolean;
/** Component exports to auto-import from solid-js (default: ["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"]) */
builtIns?: string[];
};
}
// External types from dependencies
type FilterPattern = (string | RegExp)[] | string | RegExp | null; // from 'vite'
// babel.TransformOptions is from '@babel/core' packageSSR Configuration:
solidPlugin({
ssr: true,
solid: {
generate: "ssr",
hydratable: true,
},
});Custom Extensions:
solidPlugin({
extensions: [
"mdx",
["vue", { typescript: true }],
],
});Dynamic Babel Configuration:
solidPlugin({
babel: (source, id, ssr) => ({
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
],
plugins: ssr ? [] : ["babel-plugin-jsx-remove-data-test-id"],
}),
});Advanced Solid Options:
solidPlugin({
solid: {
moduleName: "solid-js/universal",
generate: "universal",
delegateEvents: false,
contextToCustomElements: false,
builtIns: ["For", "Show", "Switch"],
},
});The plugin automatically configures Vitest for Solid.js testing:
// Automatic configuration applied:
{
test: {
environment: "jsdom", // if not SSR
server: {
deps: { external: [/solid-js/] }
},
setupFiles: ["@testing-library/jest-dom"], // if available
}
}The plugin implements these Vite plugin hooks:
The plugin handles transformation errors gracefully and provides detailed error information during development. Common issues include: