Aller au contenu principal
Version : 3.8.0

📦 plugin-css-cascade-layers

Experimental

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
attention

To use this plugin properly, it's recommended to have a solid understanding of CSS Cascade Layers, the CSS Cascade and specificity.

Installation

npm install --save @docusaurus/plugin-css-cascade-layers
astuce

If you use the preset @docusaurus/preset-classic, this plugin is automatically configured for you with the siteConfig.future.v4.useCssCascadeLayers flag.

Configuration

Champs acceptés :

NomTypePar défautDescription
layersLayersBuilt-in layersAn 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
Order matters

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

Exemple de configuration

Vous pouvez configurer ce plugin via les options du plugin.

const options = {
layers: {
'docusaurus.infima': (filePath) =>
filePath.includes('/node_modules/infima/dist'),
'docusaurus.theme-classic': (filePath) =>
filePath.includes('/node_modules/@docusaurus/theme-classic/lib'),
},
};