Skip to content

Commit

Permalink
fix: addressing comments from webpack on insert-string
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedAlchemy committed Jan 25, 2020
1 parent 7b0afeb commit 869b207
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
14 changes: 5 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,8 @@ class CssModuleFactory {
class ExtractCssChunksPlugin {
constructor(options = {}) {
validateOptions(schema, options, 'Mini CSS Extract Plugin');
const insert =
typeof options.insert === 'undefined'
? '"head"'
: typeof options.insert === 'string'
? JSON.stringify(options.insert)
: options.insert.toString();

const insert = options.insert ? options.insert.toString() : null;
this.options = Object.assign(
{
filename: DEFAULT_FILENAME,
Expand Down Expand Up @@ -382,9 +378,9 @@ class ExtractCssChunksPlugin {
'}',
])
: '',
`var insert = ${insert};`,
`if (typeof insert === 'function') { insert(linkTag); }`,
`else { var target = document.querySelector(${insert}); target && insert === 'body' ? target && target.insertBefore(linkTag,target.firstChild) : target.appendChild(linkTag); } `,
insert
? 'insert(linkTag);'
: 'var head = document.getElementsByTagName("head")[0]; head.appendChild(linkTag)',
]),
'}).then(function() {',
Template.indent(['installedCssChunks[chunkId] = 0;']),
Expand Down
3 changes: 0 additions & 3 deletions test/cases/insert-string/style.css

This file was deleted.

0 comments on commit 869b207

Please sign in to comment.