GUIDES

Vite

Add Plumeria to a Vite project, with one command or by hand.

examples/example-vite-react shows how to use @plumeria/unplugin in Vite.
The plugin compiles Plumeria styles into CSS, with HMR in development.

npx @plumeria/init detects Vite and writes this setup for you; see @plumeria/init. The rest of this page is the same setup by hand.

Installation

Terminal
pnpm i -D @plumeria/unplugin

Usage

vite.config.ts
import { defineConfig } from 'vite';
import plumeria from '@plumeria/unplugin';

export default defineConfig({
  plugins: [plumeria.vite()],
});

plumeria.vite() accepts an options object:

vite.config.ts
export default defineConfig({
  plugins: [
    plumeria.vite({
      include: ['./src/**/*.{ts,tsx}'],
      exclude: ['**/node_modules/**'],
      styleProp: 'classStyle',
    }),
  ],
});
  • include — Globs or regular expressions for the files to compile.
  • exclude — Globs or regular expressions for the files to leave out.
  • styleProp — The JSX prop that carries styles. The default is 'sx'.

These are the options a project usually sets. devEmitToDisk writes the stylesheet to disk in development, and withoutLogicalProperties / withoutPhysicalProperties reject one spelling of a property that carries both names, so the pair cannot be written; see @plumeria/unplugin for every option and its type.

plumeria.d.ts

@plumeria/core ships no prop declaration of its own, so name the styling prop your project compiles with.

For the default name (sx), reference the declaration that ships with the package, in src/ when the project has one or at the application root otherwise:

plumeria.d.ts
/// <reference types="@plumeria/core/sx" />

If you set a custom styleProp (such as 'classStyle'), declare that name instead, and keep it the same as the one in vite.config.ts; see Declaring the styling prop.

Edit on GitHub