📦 plugin-css-cascade-layers
This plugin is mostly designed to be used internally by the classic preset through the Docusaurus future.v4.useCssCascadeLayers
flag, although it can also be used as a standalone plugin. Please let us know here if you have a use case for it and help us design an API that makes sense for the future of Docusaurus.
A plugin for wrapping CSS modules of your Docusaurus site in CSS Cascade Layers. This modern CSS feature is widely supported by all browsers. It allows grouping CSS rules in layers of specificity and gives you more control over the CSS cascade.
Use this plugin to:
- apply a top-level
@layer myLayer { ... }
block rule around any CSS module, including un-layered third-party CSS. - define an explicit layer ordering
To use this plugin properly, it's recommended to have a solid understanding of CSS Cascade Layers, the CSS Cascade and specificity.
Installation
- npm
- Yarn
- pnpm
- Bun
npm install --save @docusaurus/plugin-css-cascade-layers
yarn add @docusaurus/plugin-css-cascade-layers
pnpm add @docusaurus/plugin-css-cascade-layers
bun add @docusaurus/plugin-css-cascade-layers
If you use the preset @docusaurus/preset-classic
, this plugin is automatically configured for you with the siteConfig.future.v4.useCssCascadeLayers
flag.
Configuration
Campos aceitos:
Nome | Type | Padrão | Descrição |
---|---|---|---|
layers | Layers | Built-in layers | An object representing all the CSS cascade layers you want to use, and whether the layer should be applied to a given file path. See examples and types below. |
Types
Layers
type Layers = Record<
string, // layer name
(filePath: string) => boolean // layer matcher
>;
The layers
object is defined by:
- key: the name of a layer
- value: a function to define if a given CSS module file should be in that layer
The object order matters:
- the keys order defines an explicit CSS layer order
- when multiple layers match a file path, only the first layer will apply
Example configuration
You can configure this plugin through plugin options.
const options = {
layers: {
'docusaurus.infima': (filePath) =>
filePath.includes('/node_modules/infima/dist'),
'docusaurus.theme-classic': (filePath) =>
filePath.includes('/node_modules/@docusaurus/theme-classic/lib'),
},
};