How vite-css-modules works
developvite-css-modules integrates CSS Modules directly into Vite's build pipeline by treating them as JavaScript modules. This solves several issues inherent in the default postcss-modules delegation used by Vite:
- Full Build Integration: CSS Modules are transformed into JS files that load the CSS. This allows Vite plugins (like SCSS, PostCSS, or LightningCSS) to hook into the build process and process internal dependencies.
- Module Graph Integration: By becoming JS modules, CSS Modules join Vite's module graph, enabling proper dependency resolution, bundling, and de-duplication of shared dependencies.
- Improved Error Handling: The plugin detects and throws descriptive errors for circular
composesdependencies (e.g.,Circular CSS Module dependency: "a.module.css" -> "b.module.css" -> "a.module.css") and prevents silent failures on unresolved dependencies.
This approach is conceptually similar to Webpack's css-loader.