The Vite convention does not apply
In a Vite project, UnoCSS is a bundler plugin andimport "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
Createpostcss.config.mjs at the project root:
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:In a content script
In a content script, a plainimport "../styles/uno.css" evaluates to a URL for the
stylesheet. It styles nothing by itself.
Extension.js places that sheet for you in one case only. The import must be in the entry
file of a declared content script, and the script must mark a host with
data-extension-root. The sheet then goes into the shadow root of that host, so render
your markup there:
Verify
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.filesystemglobs to source folders. A glob that reachesnode_modulesordistslows 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.

