Manual setup
The CLI in Quick start writes a whole project for you. When you are adding Solid to an existing project, starting from an empty Vite project in StackBlitz, or using a different bundler, set it up by hand instead. This page builds the smallest working app: one button that counts clicks.
Install the packages
npm install solid-js @solidjs/webnpm install -D vite @solidjs/vite-pluginsolid-js is the reactive core: signals, stores, components, and control flow.
@solidjs/web is the browser renderer, with render, hydrate, and the JSX types.
@solidjs/vite-plugin compiles JSX and connects Solid to Vite.
Configure Vite
Create vite.config.ts:
import { defineConfig } from "vite";import solid from "@solidjs/vite-plugin";
export default defineConfig({ plugins: [solid()],});In an existing Vite project, add solid() to the plugins array you already have.
Configure TypeScript
Solid compiles JSX itself, so TypeScript must leave it alone and take the JSX types from @solidjs/web:
{ "compilerOptions": { "target": "ESNext", "module": "ESNext", "moduleResolution": "bundler", "strict": true, "jsx": "preserve", "jsxImportSource": "@solidjs/web", "types": ["vite/client"], "noEmit": true }, "include": ["src"]}jsx and jsxImportSource are the two lines Solid needs.
The others are a reasonable default for a Vite project.
Add the entry files
Vite starts from index.html.
Give it an element to render into and a script tag for your entry file:
<!doctype html><html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Solid App</title> </head> <body> <div id="root"></div> <script type="module" src="/src/index.tsx"></script> </body></html>The entry file mounts the app with render:
import { render } from "@solidjs/web";import App from "./App";
render(() => <App />, document.getElementById("root")!);import { createSignal } from "solid-js";
export default function App() { const [count, setCount] = createSignal(0);
return ( <button type="button" onClick={() => setCount((c) => c + 1)}> Clicked {count()} times </button> );}Run npx vite and open the URL it prints.
The button reads "Clicked 0 times", and each click increases the number.
npx vite build writes static files to dist.
render takes a function, not an element, so that the component is created inside the root that render sets up.
It returns a function that removes the app and cleans it up.
The CLI templates use the plugin's start mode (solid({ start: true })), which generates index.html and the entry file for you and adds routing and server rendering on top.
App structure explains it.
The manual setup on this page is the plain Vite setup, without start mode.
Use another bundler
The Vite plugin uses the native compiler. Outside Vite, use one of the two compilers directly:
-
@solidjs/babel-pluginworks with any Babel pipeline, on Babel 7 or 8. Add it to your Babel configuration, after@babel/preset-typescriptif you use TypeScript:babel.config.js export default {presets: ["@babel/preset-typescript"],plugins: ["@solidjs/babel-plugin"],}; -
@solidjs/compileris the native compiler that the Vite plugin uses. It exposes atransform()function for writing your own bundler integration.
Both compile JSX to imports from @solidjs/web by default.
Keep the TypeScript settings above in either case.
Coming from Solid 1
The packages have changed: solid-js/web is now @solidjs/web, solid-js/store is part of solid-js, and @solidjs/vite-plugin replaces vite-plugin-solid.
Update the jsxImportSource in tsconfig.json from solid-js to @solidjs/web.
From Solid 1 covers the order to upgrade in and the code changes that follow.
Next steps
- Quick start: the same app built with the CLI, with routing and tests.
- Reactivity: how the counter above updates.
- Project shapes: when to move to start mode for routing and server rendering.