Skip to main content
UnoCSS is an atomic CSS engine that generates only the utility classes that your source files use. Extension.js runs it through PostCSS, the same pipeline that Tailwind uses here.

The Vite convention does not apply

In a Vite project, UnoCSS is a bundler plugin and import "uno.css" or virtual:uno.css resolves to a generated virtual module. Extension.js builds with Rspack, and the UnoCSS webpack plugin does not resolve that module there. A project that imports uno.css fails with Can't resolve 'uno.css'. Use the PostCSS plugin instead. It replaces an @unocss; directive inside a real CSS file with the generated styles, so there is no virtual module to resolve.

Installation

Configuration

Create postcss.config.mjs at the project root:
Create uno.config.ts next to it. The content.filesystem globs tell UnoCSS which files to scan for class names, because no bundler plugin feeds it the module graph here:

Usage

Create a stylesheet that carries the directive. UnoCSS replaces it with the generated CSS:
Import that file from every entry that uses utility classes:
For a content script, import the same file from the content-script entry. Extension.js routes content-script CSS through its content-script style pipeline and ships it with the script under content_scripts/.

Verify

Open the emitted stylesheet for the page under dist/chromium and look for the classes that your markup uses. If the file holds no utility rules, the content.filesystem globs do not cover the file that uses them.

Best practices

  • Keep the directive stylesheet small. Global resets and tokens belong in a separate file.
  • Scope the content.filesystem globs to source folders. A glob that reaches node_modules or dist slows every build down.
  • Import the directive stylesheet once per entry, not once per component.

Next steps

  • PostCSS: detection rules and the configuration files that Extension.js reads.
  • Tailwind CSS: the same pipeline with Tailwind.
  • CSS: how page and content-script styles are emitted.