Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: addressing comments from webpack on insert-string #226

Merged
merged 3 commits into from
Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 1 addition & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ module.exports = {

### insert

Type: `String|Function`
Type: `Function`
Default: `head`

By default, the `extract-css-chunks-plugin` appends styles (`<link>` elements) to `document.head` of the current `window`.
Expand All @@ -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 `<link>` element will be appended to the `#my-container` element.

#### `insert` as a function

Allows to override default behavior and insert styles at any position.
Expand Down
52 changes: 26 additions & 26 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -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"] }
]
}
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.