You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using 'Root-relative' urls is not recommended. You should only use it for legacy CSS files.
62
+
61
63
### Local scope
62
64
63
65
By default CSS exports all class names into a global selector scope. This is a feature which offer a local selector scope.
@@ -97,28 +99,30 @@ exports.locals = {
97
99
98
100
Camelcasing is recommended for local selectors. They are easier to use in the importing javascript module.
99
101
102
+
`url(...)` URLs in block scoped (`:local .abc`) rules behave like requests in modules:
103
+
*`./file.png` instead of `file.png`
104
+
*`module/file.png` instead of `~module/file.png`
105
+
106
+
100
107
You can use `:local(#someId)`, but this is not recommended. Use classes instead of ids.
101
108
102
109
You can configure the generated ident with the `localIdentName` query parameter (default `[hash:base64]`). Example: `css-loader?localIdentName=[path][name]---[local]---[hash:base64:5]` for easier debugging.
103
110
104
-
Note: For prerendering with extract-text-webpack-plugin you should use `css-loader/locals` instead of `style-loader!css-loader` in the prerendering bundle. It doesn't embed CSS but only exports the identifier mappings.
111
+
Note: For prerendering with extract-text-webpack-plugin you should use `css-loader/locals` instead of `style-loader!css-loader`**in the prerendering bundle**. It doesn't embed CSS but only exports the identifier mappings.
105
112
106
113
### Module mode
107
114
108
115
(experimental)
109
116
110
-
The query parameter `module` enables **CSS Module** mode. (`css-loader?module`)
117
+
See [CSS Modules](https://github.com/css-modules/css-modules).
111
118
112
-
* Local scoped by default.
113
-
*`url(...)` URLs behave like requests in modules:
114
-
*`./file.png` instead of `file.png`
115
-
*`module/file.png` instead of `~module/file.png`
119
+
The query parameter `module` enables **CSS Module** mode. (`css-loader?module`)
116
120
117
-
Thanks to [@markdalgleish](https://github.com/markdalgleish) for prior work on this topic.
121
+
This enables Local scoped CSS by default. (You can leave it with `:global(...)` or `:global` for selectors and/or rules.)
118
122
119
-
### Inheriting
123
+
### Composing CSS classes
120
124
121
-
When declaring a local class name you can inherit from another local class name.
125
+
When declaring a local class name you can compose a local class from another local class name.
122
126
123
127
```css
124
128
:local(.className) {
@@ -127,7 +131,7 @@ When declaring a local class name you can inherit from another local class name.
127
131
}
128
132
129
133
:local(.subClass) {
130
-
extends: className;
134
+
composes: className;
131
135
background: blue;
132
136
}
133
137
```
@@ -160,26 +164,25 @@ To import a local class name from another module:
160
164
161
165
```css
162
166
:local(.continueButton) {
163
-
extends: button from "library/button.css";
167
+
composes: button from "library/button.css";
164
168
background: red;
165
169
}
166
170
```
167
171
168
172
```css
169
173
:local(.nameEdit) {
170
-
extends: edit highlight from "./edit.css";
174
+
composes: edit highlight from "./edit.css";
171
175
background: red;
172
176
}
173
177
```
174
178
175
-
To import from multiple modules use multiple `extends:` rules. You can also use `url(...)` to specify the module (it behave a bit different).
179
+
To import from multiple modules use multiple `composes:` rules.
176
180
177
181
```css
178
182
:local(.className) {
179
-
extends: edit hightlight from "./edit.css";
180
-
extends: button from url("button.css");
181
-
/* equal to 'extends: button from "./button.css";' */
182
-
extends: classFromThisModule;
183
+
composes: edit hightlight from "./edit.css";
184
+
composes: button from "module/button.css";
185
+
composes: classFromThisModule;
183
186
background: red;
184
187
}
185
188
```
@@ -192,6 +195,8 @@ To include SourceMaps set the `sourceMap` query param.
192
195
193
196
I. e. the extract-text-webpack-plugin can handle them.
194
197
198
+
They are not enabled by default because they expose a runtime overhead and increase in bundle size (JS SourceMap do not). In addition to that relative paths are buggy and you need to use an absolute public path which include the server url.
199
+
195
200
### importing and chained loaders
196
201
197
202
The query parameter `importLoaders` allow to configure which loaders should be applied to `@import`ed resources.
0 commit comments