Skip to content

Commit c1f7c86

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 272910c commit c1f7c86

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
@@ -113,6 +113,7 @@ class MiniCssExtractPlugin {
113113
this.options = Object.assign(
114114
{
115115
filename: '[name].css',
116+
insertInto: null,
116117
},
117118
options
118119
);
@@ -378,8 +379,10 @@ class MiniCssExtractPlugin {
378379
'}',
379380
])
380381
: '',
381-
'var head = document.getElementsByTagName("head")[0];',
382-
'head.appendChild(linkTag);',
382+
`var selector = "${this.options.insertInto}";`,
383+
'var parent = selector && document.querySelector && document.querySelector(selector);',
384+
'if (parent) { parent.appendChild(linkTag); }',
385+
'else { document.getElementsByTagName("head")[0].appendChild(linkTag); }',
383386
]),
384387
'}).then(function() {',
385388
Template.indent(['installedCssChunks[chunkId] = 0;']),

0 commit comments

Comments
 (0)