Skip to content

Commit b5c420a

Browse files
committed
feat: convert insertInto option to be a function
1 parent c1f7c86 commit b5c420a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ class MiniCssExtractPlugin {
117117
},
118118
options
119119
);
120+
if (typeof this.options.insertInto !== 'function') {
121+
throw new Error('insertInto option must be a function');
122+
}
120123
if (!this.options.chunkFilename) {
121124
const { filename } = this.options;
122125
const hasName = filename.includes('[name]');
@@ -324,6 +327,9 @@ class MiniCssExtractPlugin {
324327
contentHashType: MODULE_TYPE,
325328
}
326329
);
330+
const insertInto = this.options.insertInto
331+
? this.options.insertInto.toString()
332+
: 'null';
327333
return Template.asString([
328334
source,
329335
'',
@@ -379,8 +385,8 @@ class MiniCssExtractPlugin {
379385
'}',
380386
])
381387
: '',
382-
`var selector = "${this.options.insertInto}";`,
383-
'var parent = selector && document.querySelector && document.querySelector(selector);',
388+
`var insertInto = ${insertInto};`,
389+
'var parent = insertInto ? insertInto(href) : null;',
384390
'if (parent) { parent.appendChild(linkTag); }',
385391
'else { document.getElementsByTagName("head")[0].appendChild(linkTag); }',
386392
]),

0 commit comments

Comments
 (0)