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
BREAKING CHANGE: the `style-loader/url` and the `style-loader/useable` were removed in favor `injectType` option (look documentation). The `singleton` option was removed (look documentation about `injectType`).
|**`injectType`**|`{String}`|`styleTag`| Allows to setup how styles will be injected in DOM |
79
+
|**`attributes`**|`{Object}`|`{}`| Add custom attributes to tag |
80
+
|**`insertAt`**|`{String\|Object}`|`bottom`| Inserts tag at the given position |
81
+
|**`insertInto`**|`{String\|Function}`|`<head>`| Inserts tag into the given position |
82
+
|**`base`**|`{Number}`|`true`| Set module ID base (DLLPlugin) |
83
+
84
+
### `injectType`
85
+
86
+
Type: `String`
87
+
Default: `styleTag`
88
+
89
+
Allows to setup how styles will be injected in DOM.
75
90
76
-
The `style-loader` injects the styles lazily making them useable on-demand via `style.use()` / `style.unuse()`
91
+
Possible values:
92
+
93
+
-`styleTag`
94
+
-`singletonStyleTag`
95
+
-`lazyStyleTag`
96
+
-`lazySingletonStyleTag`
97
+
-`linkTag`
98
+
99
+
When you `lazyStyleTag` or `lazySingletonStyleTag` value the `style-loader` injects the styles lazily making them useable on-demand via `style.use()` / `style.unuse()`.
100
+
It is named `Reference Counter API`.
101
+
102
+
**component.js**
103
+
104
+
```js
105
+
importstylefrom'./file.css';
106
+
107
+
style.use(); // = style.ref();
108
+
style.unuse(); // = style.unref();
109
+
```
77
110
78
111
By convention the `Reference Counter API` should be bound to `.useable.css` and the `.css` should be loaded with basic `style-loader` usage.(similar to other file types, i.e. `.useable.less` and `.less`).
// Can be `'lazyStyleTag'` or `'lazySingletonStyleTag'`
131
+
injectType:'lazyStyleTag',
132
+
},
96
133
},
97
134
{ loader:'css-loader' },
98
135
],
@@ -102,27 +139,57 @@ module.exports = {
102
139
};
103
140
```
104
141
105
-
#### `Reference Counter API`
142
+
Styles are not added on `import/require()`, but instead on call to `use`/`ref`. Styles are removed from page if `unuse`/`unref` is called exactly as often as `use`/`ref`.
106
143
107
-
**component.js**
144
+
> ⚠️ Behavior is undefined when `unuse`/`unref` is called more often than `use`/`ref`. Don't do that.
145
+
146
+
#### `styleTag`
147
+
148
+
Injects styles in multiple `<style></style>`. It is **default** behaviour.
Styles are not added on `import/require()`, but instead on call to `use`/`ref`. Styles are removed from page if `unuse`/`unref` is called exactly as often as `use`/`ref`.
172
+
The loader inject styles like:
117
173
118
-
> ⚠️ Behavior is undefined when `unuse`/`unref` is called more often than `use`/`ref`. Don't do that.
174
+
```html
175
+
<style>
176
+
.foo {
177
+
color: red;
178
+
}
179
+
</style>
180
+
<style>
181
+
.bar {
182
+
color: blue;
183
+
}
184
+
</style>
185
+
```
119
186
120
-
###`Url`
187
+
#### `singletonStyleTag`
121
188
122
-
It's also possible to add a URL `<link href="path/to/file.css" rel="stylesheet">` instead of inlining the CSS `{String}` with `<style></style>` tag.
|**`base`**|`{Number}`|`true`| Set module ID base (DLLPlugin) |
152
-
|**`attributes`**|`{Object}`|`{}`| Add custom attributes to `<style></style>`|
153
-
|**`insertAt`**|`{String\|Object}`|`bottom`| Inserts `<style></style>` at the given position |
154
-
|**`insertInto`**|`{String\|Function}`|`<head>`| Inserts `<style></style>` into the given position |
155
-
|**`singleton`**|`{Boolean}`|`undefined`| Reuses a single `<style></style>` element, instead of adding/removing individual elements for each required module. |
231
+
Injects styles in multiple `<style></style>` on demand (documentation above).
156
232
157
-
### `base`
233
+
```js
234
+
importstylesfrom'./styles.css';
158
235
159
-
This setting is primarily used as a workaround for [css clashes](https://github.com/webpack-contrib/style-loader/issues/163) when using one or more [DllPlugin](https://robertknight.github.io/posts/webpack-dll-plugins/)'s. `base` allows you to prevent either the _app_'s css (or _DllPlugin2_'s css) from overwriting _DllPlugin1_'s css by specifying a css module id base which is greater than the range used by _DllPlugin1_ e.g.:
If defined, the style-loader will reuse a single `<style></style>` element, instead of adding/removing individual elements for each required module.
495
+
This setting is primarily used as a workaround for [css clashes](https://github.com/webpack-contrib/style-loader/issues/163) when using one or more [DllPlugin](https://robertknight.github.io/posts/webpack-dll-plugins/)'s. `base` allows you to prevent either the _app_'s css (or _DllPlugin2_'s css) from overwriting _DllPlugin1_'s css by specifying a css module id base which is greater than the range used by _DllPlugin1_ e.g.:
360
496
361
-
> ℹ️ This option is on by default in IE9, which has strict limitations on the number of style tags allowed on a page. You can enable or disable it with the singleton option.
"description": "Reuses a single <style></style> element, instead of adding/removing individual elements for each required module (https://github.com/webpack-contrib/style-loader#singleton).",
"Invalid options object. Style Loader has been initialised using an options object that does not match the API schema.
35
-
- options.singleton should be a boolean.
36
-
-> Reuses a single <style></style> element, instead of adding/removing individual elements for each required module (https://github.com/webpack-contrib/style-loader#singleton)."
37
-
`;
38
-
39
-
exports[`validate options 6`] =`
40
35
"Invalid options object. Style Loader has been initialised using an options object that does not match the API schema.
41
36
- options has an unknown property 'unknown'. These properties are valid:
0 commit comments