Skip to content

Commit 0846785

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 0846785

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class MiniCssExtractPlugin {
132132
);
133133
}
134134
}
135+
if (!this.options.insertInto) {
136+
this.options.insertInto = 'head';
137+
}
135138
}
136139

137140
apply(compiler) {
@@ -378,8 +381,11 @@ class MiniCssExtractPlugin {
378381
'}',
379382
])
380383
: '',
381-
'var head = document.getElementsByTagName("head")[0];',
382-
'head.appendChild(linkTag);',
384+
`var parent = document.querySelector("${
385+
this.options.insertInto
386+
}");`,
387+
'if (parent) { parent.appendChild(linkTag); }',
388+
'else { reject("Invalid parent element"); }',
383389
]),
384390
'}).then(function() {',
385391
Template.indent(['installedCssChunks[chunkId] = 0;']),

0 commit comments

Comments
 (0)