Browse documentation

Reference / Installation

Using Vite

Build Mono utilities into a local stylesheet and let Vite serve it during development and bundle it for production.

Create a Vite app

Use npm and a Node.js version supported by your Vite release. If you already have a Vite app, start in its project directory and continue with the next step.

Terminal
npm create vite@latest mono-app -- --template vanilla
cd mono-app
npm install

Install Mono from the checkout

Replace /absolute/path/to/baseframework with the folder that contains Mono’s package.json. Installing it as a development dependency makes the mono command available to your npm scripts.

Terminal
npm install -D /absolute/path/to/baseframework

Choose the source files

Create this file at the root of your Vite app. Mono will scan index.html and your components, then write its stylesheet inside src so Vite can track it.

mono.config.mjs
export default {
  content: ['./index.html', './src/**/*.{html,js,jsx,ts,tsx,vue,svelte}'],
  output: './src/mono.css',
}

Connect your stylesheet

For a minimal vanilla app, replace the starter index.html with this page. If you are keeping your application, add the stylesheet link to the existing head and use the sample classes on one of your components.

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Mono with Vite</title>
    <link rel="stylesheet" href="/src/mono.css">
  </head>
  <body>
    <main class="mx-auto max-w-lg p-6 md:p-12">
      <h1 class="text-3xl font-bold">Hello from Mono.</h1>
      <p class="mt-3 leading-relaxed">Edit a class and save this file.</p>
    </main>
  </body>
</html>

Start the compiler and Vite

In the first terminal, start Mono and wait for its initial build. In a second terminal, run Vite from the same directory. Open the address Vite prints, change text-3xl to text-4xl, and save. The heading will update.

Terminal 1
npm exec -- mono build --watch
Terminal 2
npm run dev

Build for production

Add the prebuild entry to your existing npm scripts. Keep the app’s existing build command. npm runs prebuild before build, so Vite always bundles a fresh stylesheet. The vanilla template writes the production site to dist/.

package.json · scripts fragment
{
  "scripts": {
    "dev": "vite",
    "prebuild": "mono build --minify",
    "build": "vite build",
    "preview": "vite preview"
  }
}
Terminal
npm run build
npm run preview