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
Copy file name to clipboardExpand all lines: README.md
+44Lines changed: 44 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -578,6 +578,50 @@ module.exports = {
578
578
};
579
579
```
580
580
581
+
### insert
582
+
583
+
Type: `String|Function`
584
+
Default: `head`
585
+
586
+
By default, the `extract-css-chunks-plugin` appends styles (`<link>` elements) to `document.head` of the current `window`.
587
+
588
+
However in some circumstances it might be necessary to have finer control over the append target or even delay `link` elements instertion. For example this is the case when you asynchronously load styles for an application that runs inside of an iframe. In such cases `insert` can be configured to be a function or a custom selector.
589
+
590
+
If you target an [iframe](https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement) make sure that the parent document has sufficient access rights to reach into the frame document and append elements to it.
591
+
592
+
#### `insert` as a string
593
+
594
+
Allows to configure a [CSS selector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) that will be used to find the element where to append the styles (`link` elements).
595
+
596
+
```js
597
+
newMiniCssExtractPlugin({
598
+
insert:'#my-container',
599
+
});
600
+
```
601
+
602
+
A new `<link>` element will be appended to the `#my-container` element.
603
+
604
+
#### `insert` as a function
605
+
606
+
Allows to override default behavior and insert styles at any position.
607
+
608
+
> ⚠ Do not forget that this code will run in the browser alongside your application. Since not all browsers support latest ECMA features like `let`, `const`, `arrow function expression` and etc we recommend you to use only ECMA 5 features and syntax.
609
+
610
+
> ⚠ The `insert` function is serialized to string and passed to the plugin. This means that it won't have access to the scope of the webpack configuration module.
A new `<link>` element will be inserted before the element with id `some-element`.
624
+
581
625
### Media Query Plugin
582
626
583
627
If you'd like to extract the media queries from the extracted CSS (so mobile users don't need to load desktop or tablet specific CSS anymore) you should use one of the following plugins:
0 commit comments