Skip to content

Commit e0ec27d

Browse files
committed
feat(ordering): add support for insertInto option
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
1 parent 392c4ae commit e0ec27d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class MiniCssExtractPlugin {
125125
{
126126
filename: DEFAULT_FILENAME,
127127
moduleFilename: () => options.filename || DEFAULT_FILENAME,
128+
insertInto: null,
128129
},
129130
options
130131
);
@@ -418,8 +419,10 @@ class MiniCssExtractPlugin {
418419
'}',
419420
])
420421
: '',
421-
'var head = document.getElementsByTagName("head")[0];',
422-
'head.appendChild(linkTag);',
422+
`var selector = "${this.options.insertInto}";`,
423+
'var parent = selector && document.querySelector && document.querySelector(selector);',
424+
'if (parent) { parent.appendChild(linkTag); }',
425+
'else { document.getElementsByTagName("head")[0].appendChild(linkTag); }',
423426
]),
424427
'}).then(function() {',
425428
Template.indent(['installedCssChunks[chunkId] = 0;']),

0 commit comments

Comments
 (0)