diff --git a/README.md b/README.md index 6cc97aeb..00d27425 100644 --- a/README.md +++ b/README.md @@ -581,7 +581,7 @@ module.exports = { ### insert -Type: `String|Function` +Type: `Function` Default: `head` By default, the `extract-css-chunks-plugin` appends styles (`` elements) to `document.head` of the current `window`. @@ -590,18 +590,6 @@ However in some circumstances it might be necessary to have finer control over t If you target an [iframe](https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement) make sure that the parent document has sufficient access rights to reach into the frame document and append elements to it. -#### `insert` as a string - -Allows to configure a [CSS selector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) that will be used to find the element where to append the styles (`link` elements). - -```js -new ExtractCssChunksPlugin({ - insert: '#my-container', -}); -``` - -A new `` element will be appended to the `#my-container` element. - #### `insert` as a function Allows to override default behavior and insert styles at any position. diff --git a/renovate.json b/renovate.json index 6c86d39f..4f405116 100644 --- a/renovate.json +++ b/renovate.json @@ -1,31 +1,31 @@ { "extends": [ - ":combinePatchMinorReleases", - ":ignoreUnstable", - ":prImmediately", - ":semanticPrefixFixDepsChoreOthers", - ":updateNotScheduled", - ":automergeDisabled", - ":ignoreModulesAndTests", - ":maintainLockFilesDisabled", - ":autodetectPinVersions", - ":prHourlyLimit4", - ":prConcurrentLimit20", - "group:monorepos", - "group:recommended", - "helpers:disableTypesNodeMajor", - ":pinAllExceptPeerDependencies", - ":pinOnlyDevDependencies" + ":combinePatchMinorReleases", + ":ignoreUnstable", + ":prImmediately", + ":semanticPrefixFixDepsChoreOthers", + ":updateNotScheduled", + ":automergeDisabled", + ":ignoreModulesAndTests", + ":maintainLockFilesDisabled", + ":autodetectPinVersions", + ":prHourlyLimit4", + ":prConcurrentLimit20", + "group:monorepos", + "group:recommended", + "helpers:disableTypesNodeMajor", + ":pinAllExceptPeerDependencies", + ":pinOnlyDevDependencies" ], "packageRules": [ - { - "packageNames": ["normalize-url"], - "allowedVersions": "1.9.1" - }, - { - "packageNames": ["schema-utils"], - "allowedVersions": "^1" - }, - {"updateTypes": ["minor", "patch","pin", "digest"]} - ] + { + "packageNames": ["normalize-url"], + "allowedVersions": "1.9.1" + }, + { + "packageNames": ["schema-utils"], + "allowedVersions": "^1" + }, + { "updateTypes": ["minor", "patch", "pin", "digest"] } + ] } diff --git a/src/index.js b/src/index.js index 63c3a24b..bc4041df 100644 --- a/src/index.js +++ b/src/index.js @@ -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, @@ -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;']), diff --git a/test/cases/insert-string/style.css b/test/cases/insert-string/style.css deleted file mode 100644 index 67ce83e4..00000000 --- a/test/cases/insert-string/style.css +++ /dev/null @@ -1,3 +0,0 @@ -body { - background: red; -}