In an extension, CSS files play a key role in defining the visual style of popups, options pages, new tab pages, and injected content. Extension.js ensures that CSS files defined in the manifest.json
or included in HTML files are properly processed, supporting popular pre-processors like Sass, Less, and standard CSS.
Extension.js offers first-class support for CSS and its pre-processor variants (e.g., .scss
, .sass
, .less
). These styles can be used in both content_scripts
and HTML pages with their original extensions, making development flexible and modern. Additionally, hot-module replacement (HMR) is supported for CSS during development, ensuring rapid feedback and live updates.
The following manifest fields are supported for CSS files:
Manifest Field | File Type Expected | HMR Support |
---|---|---|
content_scripts.css |
.css, .scss, .sass, .less | Yes |
background.page |
.css, .scss, .sass, .less | Yes |
action.default_popup |
.css, .scss, .sass, .less | Yes |
chrome_url_overrides.newtab |
.css, .scss, .sass, .less | Yes |
options_ui.page |
.css, .scss, .sass, .less | Yes |
devtools_page |
.css, .scss, .sass, .less | Yes |
manifest.json
Hereβs a basic example of adding CSS files to content_scripts
in the manifest.json
:
CSS can be directly imported in HTML files, with full support for pre-processors like Less and Sass. Simply include the styles with their original extensions, and Extension.js will handle the compilation and injection of these styles:
The output path for CSS files follows the same logic as scripts or HTML. The CSS will be bundled into [feature]/index.css
for styles imported in HTML files, based on where it's used. For example, for a newtab
override, the resulting files would look like this:
For the CSS that represents content scripts in the manifest.json
file, the output path will be:
The plugin for CSS file support in Extension.js ensures that the following steps occur during compilation:
/styles
folder are added to the compilation.content_scripts
to benefit from HMR..scss
, .sass
, and .less
extensions are fully supported and compiled during the build process.