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
By default, the style-loader appends `<style>` elements to the end of the style target, which is the `<head>` tag of the page unless specified by `insertInto`. This will cause CSS created by the loader to take priority over CSS already present in the target. To insert style elements at the beginning of the target, set this query parameter to 'top', e.g
385
+
Type: `String|Function`
386
+
Default: `head`
387
387
388
-
**webpack.config.js**
388
+
By default, the `style-loader` appends `<style>`/`<link>` elements to the end of the style target, which is the `<head>` tag of the page unless specified by `insert`.
389
+
This will cause CSS created by the loader to take priority over CSS already present in the target.
390
+
You can use other values if the standard behavior is not suitable for you, but we do not recommend doing this.
391
+
If you target an [iframe](https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement) make sure you have sufficient access rights, the styles will be injected into the content document head.
389
392
390
-
```js
391
-
module.exports= {
392
-
module: {
393
-
rules: [
394
-
{
395
-
test:/\.css$/i,
396
-
use: [
397
-
{
398
-
loader:'style-loader',
399
-
options: {
400
-
insertAt:'top',
401
-
},
402
-
},
403
-
{ loader:'css-loader' },
404
-
],
405
-
},
406
-
],
407
-
},
408
-
};
409
-
```
393
+
#### `String`
410
394
411
-
A new `<style>` element can be inserted before a specific element by passing an object, e.g.
395
+
Allows to setup custom [query selector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) where styles inject into DOM.
412
396
413
397
**webpack.config.js**
414
398
@@ -422,49 +406,25 @@ module.exports = {
422
406
{
423
407
loader:'style-loader',
424
408
options: {
425
-
insertAt: {
426
-
before:'#id',
427
-
},
409
+
insert:'body',
428
410
},
429
411
},
430
-
{ loader:'css-loader' },
412
+
'css-loader',
431
413
],
432
414
},
433
415
],
434
416
},
435
417
};
436
418
```
437
419
438
-
### `insertInto`
420
+
A new `<style>`/`<link>` elements will be inserted into at bottom of `body` tag.
439
421
440
-
By default, the style-loader inserts the `<style>` elements into the `<head>` tag of the page. If you want the tags to be inserted somewhere else you can specify a CSS selector for that element here. If you target an [IFrame](https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement) make sure you have sufficient access rights, the styles will be injected into the content document head.
422
+
#### `Function`
441
423
442
-
You can also pass function to override default behavior and insert styles in your container, e.g
424
+
Allows to override default behavior and insert styles at any position.
443
425
444
-
**webpack.config.js**
445
-
446
-
```js
447
-
module.exports= {
448
-
module: {
449
-
rules: [
450
-
{
451
-
test:/\.css$/i,
452
-
use: [
453
-
{
454
-
loader:'style-loader',
455
-
options: {
456
-
insertInto: () =>document.querySelector('#root'),
457
-
},
458
-
},
459
-
{ loader:'css-loader' },
460
-
],
461
-
},
462
-
],
463
-
},
464
-
};
465
-
```
466
-
467
-
Using function you can insert the styles into a [ShadowRoot](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot), e.g
426
+
> ⚠ Do not forget that this code will be used in the browser and not all browsers support latest ECMA features like `let`, `const`, `arrow function expression` and etc, we recommend use only ECMA 5 features, but it is depends what browsers you want to support
427
+
> ⚠ Do not forget that some doom methods may not be available in older browsers, we recommended use only [DOM core level 2 properties](https://caniuse.com/#search=DOM%20Core), but it is depends what browsers you want to support
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.:
@@ -581,9 +554,9 @@ There are two ways to work with `nonce`:
581
554
- using the `attirbutes` option
582
555
- using the `__webpack_nonce__` variable
583
556
584
-
> ⚠ the `__webpack_nonce__` variable takes precedence over the `attibutes` option, so if define the `__webpack_nonce__` variable the `attributes` option will not be used
557
+
> ⚠ the `attibutes` option takes precedence over the `__webpack_nonce__` variable
0 commit comments