Vite
Bundle Chassis CSS and JavaScript with Vite — Sass setup, Vite config, and token resolution.
Vite is a fast, modern frontend build tool. This guide walks through a fresh project; if you already have Vite set up, jump to Import Chassis.
Installation covers the moving parts — the only Vite-specific work here is configuring the Sass preprocessor options.
Setup
This guide assumes Node.js is installed and you're comfortable in a terminal.
-
Create a project folder and initialize npm.
mkdir my-project && cd my-project pnpm init -
Install Vite.
pnpm add -D vite -
Install Chassis CSS and its tokens. Add the optional peer dependencies for the components that need them, or omit both and use
chassis.bundle.*which includes them.pnpm add @chassis-ui/css @chassis-ui/tokens pnpm add @floating-ui/dom vanilla-calendar-pro # optional -
Install Sass. Vite handles
.scssfiles when Sass is present.pnpm add -D sass
Project structure
Create the source folders and starter files:
mkdir -p src/js src/scss
touch src/index.html src/js/main.js src/scss/styles.scss vite.config.jsThe result:
my-project/
├── src/
│ ├── js/
│ │ └── main.js
│ ├── scss/
│ │ └── styles.scss
│ └── index.html
├── package.json
├── pnpm-lock.yaml
└── vite.config.jsConfigure Vite
The steps below fill in vite.config.js, the starter HTML, and the npm scripts needed to run and build the project.
-
Fill in
vite.config.js. This config tells Vite where the source lives, where to emit the build, and which port the dev server should use. TheloadPathsentry lets Sass resolve token overrides placed insrc/scss.import { resolve } from 'path' export default { root: resolve(__dirname, 'src'), build: { outDir: '../dist' }, server: { port: 8080 }, css: { preprocessorOptions: { scss: { loadPaths: [resolve(__dirname, 'src/scss')] // project token override } } } } -
Fill in
src/index.html.<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Chassis CSS w/ Vite</title> <script type="module" src="./js/main.js"></script> </head> <body> <div class="container py-large px-medium mx-auto"> <h1>Hello, Chassis CSS and Vite!</h1> <button class="button primary">Primary button</button> </div> </body> </html> -
Add the
startandbuildscripts topackage.json.{ "scripts": { "start": "vite", "build": "vite build" } } -
Start the dev server.
pnpm startVite opens a local server on
http://localhost:8080. The page won't be styled yet — the stylesheet and entry script still need to be filled in.
Import Chassis
Vite needs a Sass entry point that imports Chassis. The loadPaths entry in vite.config.js ensures Sass can resolve token overrides from src/scss.
-
Fill in
src/scss/styles.scss. The token source resolves through_vendor.scssbefore the rest of Chassis processes its variables, so a single@usedirective is all that's needed.// Chassis CSS — token source resolves via the loadPaths entry in vite.config.js @use "@chassis-ui/css/scss/chassis"; // Optional: settings overrides use the `with (...)` syntax // @use "@chassis-ui/css/scss/chassis" with ( // $enable-fluid-font-sizes: false, // $enable-component-shadows: true, // );The default token build (
chassis/docs) is resolved automatically. To switch to a custom token set, place a_chassis-tokens.scsson an earlierloadPathsentry — see Customize → Sass for details. -
Import the stylesheet and Chassis JS in
src/js/main.js. Floating UI and vanilla-calendar-pro are resolved through the bundler when needed.import '../scss/styles.scss' import * as chassis from '@chassis-ui/css'For smaller bundles, import only the required plugins:
import { Modal, Tooltip } from '@chassis-ui/css' -
Reload. With both files filled in, Vite hot-reloads the page — the heading and button should now render with Chassis styling.
Build optimizations
Unlike webpack's style-loader, Vite never injects CSS via a <style> tag — it always emits a separate .css file when running vite build. No additional plugin is needed for CSS extraction.
Next steps
These docs cover JavaScript integration, Sass customization, and bundle optimization for a Vite-based Chassis project.
- JavaScript — using the JS plugins, the programmatic API, and event names.
- Customize → Sass — variable overrides and importing only the required partials.
- Customize → Optimize — keeping the Chassis output lean.