Skip to content

Commit

Permalink
feat(ordering): add support for insertInto option
Browse files Browse the repository at this point in the history
This adds an new `insertInto` option that is optional and backards-compatible.  Specifying a CSS selector allows the user to specify a DOM node into which the async-loaded <link> tags should be inserted.

Closes webpack-contrib#370, related to webpack-contrib#328,webpack-contrib#331
  • Loading branch information
brophdawg11 committed Apr 1, 2019
1 parent 272910c commit c1f7c86
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class MiniCssExtractPlugin {
this.options = Object.assign(
{
filename: '[name].css',
insertInto: null,
},
options
);
Expand Down Expand Up @@ -378,8 +379,10 @@ class MiniCssExtractPlugin {
'}',
])
: '',
'var head = document.getElementsByTagName("head")[0];',
'head.appendChild(linkTag);',
`var selector = "${this.options.insertInto}";`,
'var parent = selector && document.querySelector && document.querySelector(selector);',
'if (parent) { parent.appendChild(linkTag); }',
'else { document.getElementsByTagName("head")[0].appendChild(linkTag); }',
]),
'}).then(function() {',
Template.indent(['installedCssChunks[chunkId] = 0;']),
Expand Down

0 comments on commit c1f7c86

Please sign in to comment.