Skip to content
This repository was archived by the owner on May 31, 2021. It is now read-only.

Commit d41bafa

Browse files
fix: addressing comments from webpack on insert-string (faceyspacey#226)
* fix: addressing comments from webpack on insert-string * style: lint renovate * docs: remove insert string option
1 parent 7b0afeb commit d41bafa

File tree

4 files changed

+32
-51
lines changed

4 files changed

+32
-51
lines changed

README.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ module.exports = {
581581

582582
### insert
583583

584-
Type: `String|Function`
584+
Type: `Function`
585585
Default: `head`
586586

587587
By default, the `extract-css-chunks-plugin` appends styles (`<link>` 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
590590

591591
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.
592592

593-
#### `insert` as a string
594-
595-
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).
596-
597-
```js
598-
new ExtractCssChunksPlugin({
599-
insert: '#my-container',
600-
});
601-
```
602-
603-
A new `<link>` element will be appended to the `#my-container` element.
604-
605593
#### `insert` as a function
606594

607595
Allows to override default behavior and insert styles at any position.

renovate.json

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
{
22
"extends": [
3-
":combinePatchMinorReleases",
4-
":ignoreUnstable",
5-
":prImmediately",
6-
":semanticPrefixFixDepsChoreOthers",
7-
":updateNotScheduled",
8-
":automergeDisabled",
9-
":ignoreModulesAndTests",
10-
":maintainLockFilesDisabled",
11-
":autodetectPinVersions",
12-
":prHourlyLimit4",
13-
":prConcurrentLimit20",
14-
"group:monorepos",
15-
"group:recommended",
16-
"helpers:disableTypesNodeMajor",
17-
":pinAllExceptPeerDependencies",
18-
":pinOnlyDevDependencies"
3+
":combinePatchMinorReleases",
4+
":ignoreUnstable",
5+
":prImmediately",
6+
":semanticPrefixFixDepsChoreOthers",
7+
":updateNotScheduled",
8+
":automergeDisabled",
9+
":ignoreModulesAndTests",
10+
":maintainLockFilesDisabled",
11+
":autodetectPinVersions",
12+
":prHourlyLimit4",
13+
":prConcurrentLimit20",
14+
"group:monorepos",
15+
"group:recommended",
16+
"helpers:disableTypesNodeMajor",
17+
":pinAllExceptPeerDependencies",
18+
":pinOnlyDevDependencies"
1919
],
2020
"packageRules": [
21-
{
22-
"packageNames": ["normalize-url"],
23-
"allowedVersions": "1.9.1"
24-
},
25-
{
26-
"packageNames": ["schema-utils"],
27-
"allowedVersions": "^1"
28-
},
29-
{"updateTypes": ["minor", "patch","pin", "digest"]}
30-
]
21+
{
22+
"packageNames": ["normalize-url"],
23+
"allowedVersions": "1.9.1"
24+
},
25+
{
26+
"packageNames": ["schema-utils"],
27+
"allowedVersions": "^1"
28+
},
29+
{ "updateTypes": ["minor", "patch", "pin", "digest"] }
30+
]
3131
}

src/index.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,8 @@ class CssModuleFactory {
101101
class ExtractCssChunksPlugin {
102102
constructor(options = {}) {
103103
validateOptions(schema, options, 'Mini CSS Extract Plugin');
104-
const insert =
105-
typeof options.insert === 'undefined'
106-
? '"head"'
107-
: typeof options.insert === 'string'
108-
? JSON.stringify(options.insert)
109-
: options.insert.toString();
104+
105+
const insert = options.insert ? options.insert.toString() : null;
110106
this.options = Object.assign(
111107
{
112108
filename: DEFAULT_FILENAME,
@@ -382,9 +378,9 @@ class ExtractCssChunksPlugin {
382378
'}',
383379
])
384380
: '',
385-
`var insert = ${insert};`,
386-
`if (typeof insert === 'function') { insert(linkTag); }`,
387-
`else { var target = document.querySelector(${insert}); target && insert === 'body' ? target && target.insertBefore(linkTag,target.firstChild) : target.appendChild(linkTag); } `,
381+
insert
382+
? 'insert(linkTag);'
383+
: 'var head = document.getElementsByTagName("head")[0]; head.appendChild(linkTag)',
388384
]),
389385
'}).then(function() {',
390386
Template.indent(['installedCssChunks[chunkId] = 0;']),

test/cases/insert-string/style.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)