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
new extends syntax
added :global and :local
added module mode
removed old deprecated syntax
breaking change if you are using local scope (it was experimental)
Copy file name to clipboardExpand all lines: README.md
+41-12
Original file line number
Diff line number
Diff line change
@@ -64,44 +64,60 @@ By default CSS exports all class names into a global selector scope. This is a f
64
64
65
65
The syntax `:local(.className)` can be used to declare `className` in the local scope. The local identifiers are exported by the module.
66
66
67
-
It does it by replacing the selectors by unique identifiers. The choosen unique identifiers are exported by the module.
67
+
With `:local` (without brackets) local mode can be switched on for this selector. `:global(.className)` can be used to declare an explicit global selector. With `:global` (without brackets) global mode can be switched on for this selector.
68
+
69
+
The loader replaces local selectors with unique identifiers. The choosen unique identifiers are exported by the module.
Camelcasing is recommended for local selectors. They are easier to use in the importing javascript module.
99
+
100
+
You can use `:local(#someId)`, but this is not recommended. Use classes instead of ids.
101
+
97
102
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.
98
103
99
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.
100
105
101
-
### Inheriting
106
+
### Module mode
102
107
103
108
(experimental)
104
109
110
+
The query parameter `module` enables **CSS module** mode. (`css-loader?module`)
111
+
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`
116
+
117
+
Thanks to @markdalgleish for prior work on this topic.
118
+
119
+
### Inheriting
120
+
105
121
When declaring a local class name you can inherit from another local class name.
106
122
107
123
```css
@@ -110,7 +126,8 @@ When declaring a local class name you can inherit from another local class name.
110
126
color: yellow;
111
127
}
112
128
113
-
:local(.subClass):extends(.className) {
129
+
:local(.subClass) {
130
+
extends: className;
114
131
background: blue;
115
132
}
116
133
```
@@ -139,18 +156,30 @@ and CSS is transformed to:
139
156
140
157
### Importing local class names
141
158
142
-
(experimental)
143
-
144
159
To import a local class name from another module:
145
160
146
161
```css
147
-
:local(.continueButton):extends(.button from "library/button.css") {
162
+
:local(.continueButton) {
163
+
extends: button from "library/button.css";
148
164
background: red;
149
165
}
150
166
```
151
167
152
168
```css
153
-
:local(.nameEdit):extends(.edit.highlight from "./edit.css") {
169
+
:local(.nameEdit) {
170
+
extends: edit highlight from "./edit.css";
171
+
background: red;
172
+
}
173
+
```
174
+
175
+
To import from multiple modules use multiple `extends:` rules. You can also use `url(...)` to specify the module (it behave a bit different).
176
+
177
+
```css
178
+
:local(.className) {
179
+
extends: edit hightlight from "./edit.css";
180
+
extends: button from url("button.css");
181
+
/* equal to 'extends: button from "./button.css";' */
0 commit comments