Installation

Set up Master CSS in Vite

Vite

Guide to setting up Master CSS in your Vite project.

Master CSS Static Extraction integrates build tools to scan project source code, extract class names, generate CSS rules, and write them into a virtual CSS module.

Zero runtime

Generate virtual CSS modules at build time

Semi-dynamic

Scan all source code to extract class names

Cross-page caching

Download the CSS bundle for all pages at once


Quick start

Clone the example

Copy-paste the commands to quickly start using the https://vite.se.rc.css.master.co example.

You can skip all installation steps.

npm create @master/css@rc project --example vite-with-static-extraction
cd project
npm run dev

Installation

Create a project

If you don't have a Vite project, create one first. It's recommended to refer to Getting Started - Vite

npm create vite@latest project -- --template vanilla-ts
cd project
npm install

Install Master CSS Extractor

Install the Master CSS extractor into your project via package managers.

npm install @master/css-extractor.vite@rc

Initialize configuration file

Run npm create @master/css@rc to create a configuration file master.css.ts.

npm create @master/css@rc

Set up CSS extractor

  • Create a vite.config.ts file
  • Add a CSSExtractorPlugin to the vite plugins
import { defineConfig } from 'vite'
import CSSExtractorPlugin from '@master/css-extractor.vite'
export default defineConfig({
plugins: [
CSSExtractorPlugin()
]
})

Import virtual CSS module

Import the virtual CSS module .virtual/master.css into the main.ts.

import './style.css'
import '.virtual/master.css'

Launch server

Run the Vite development server.

npm run dev -- --open

Hello world!

Now style your first element using Master CSS syntax!

<!DOCTYPE html>
<html lang="en" style="display: none">
<body>
<h1 class="font:40 font:heavy italic m:12x text:center">Hello World</h1>
</body>
</html>

Open your browser to watch the changes.

localhost:5173

Hello World

© Aoyue Design LLC.