Skip to content

Commit 56dabe7

Browse files
committed
feat: convert insertInto option to be a function
1 parent e0ec27d commit 56dabe7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ class MiniCssExtractPlugin {
129129
},
130130
options
131131
);
132-
132+
if (typeof this.options.insertInto !== 'function') {
133+
throw new Error('insertInto option must be a function');
134+
}
133135
if (!this.options.chunkFilename) {
134136
const { filename } = this.options;
135137

@@ -363,7 +365,9 @@ class MiniCssExtractPlugin {
363365
contentHashType: MODULE_TYPE,
364366
}
365367
);
366-
368+
const insertInto = this.options.insertInto
369+
? this.options.insertInto.toString()
370+
: 'null';
367371
return Template.asString([
368372
source,
369373
'',
@@ -419,8 +423,8 @@ class MiniCssExtractPlugin {
419423
'}',
420424
])
421425
: '',
422-
`var selector = "${this.options.insertInto}";`,
423-
'var parent = selector && document.querySelector && document.querySelector(selector);',
426+
`var insertInto = ${insertInto};`,
427+
'var parent = insertInto ? insertInto(href) : null;',
424428
'if (parent) { parent.appendChild(linkTag); }',
425429
'else { document.getElementsByTagName("head")[0].appendChild(linkTag); }',
426430
]),

0 commit comments

Comments
 (0)