CSS Preprocessing in Vite
You'll learn how Vite handles Sass, Less, and Stylus with zero configuration beyond installing the preprocessor itself.
The Core Idea
Vite has built-in support for CSS preprocessors—you don't need complex plugins or configuration files. Simply install the preprocessor package you want to use, and Vite automatically recognizes and processes files with the corresponding extensions (.scss, .sass, .less, .styl).
Think of it like adding a language translator to your team. Once the translator (preprocessor) is present, Vite automatically routes conversations (file imports) through them without you needing to explain how translation should work.
How It Works
To use Sass in your Vite project, just run:
npm install -D sass
Then import Sass files directly in your JavaScript:
import './styles.scss';
Or in your HTML:
<link rel="stylesheet" href="./styles.scss">
The same pattern applies to Less (npm install -D less) and Stylus (npm install -D stylus). Vite detects the file extension and processes it accordingly—no vite.config.js changes needed.
Why This Matters
Unlike older build tools where you'd configure loaders, rules, and plugins for each preprocessor, Vite's zero-config approach means you get preprocessor features (variables, nesting, mixins) instantly. The preprocessors compile during development and are bundled efficiently for production automatically.
Key Takeaway: Vite supports Sass, Less, and Stylus out of the box—just npm install the preprocessor and import your files; no configuration required.