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 compatibility with webpack 5 #698

Merged
merged 20 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: compatibility with webpack v5
  • Loading branch information
alexander-akait committed Feb 9, 2021
commit 661bfd9000b8e023fe4f0ece375ae3b2b6d4bcc9
16 changes: 14 additions & 2 deletions src/CssLoadingRuntimeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,26 @@ module.exports = class CssLoadingRuntimeModule extends RuntimeModule {
RuntimeGlobals.hmrDownloadUpdateHandlers
);

if (!withLoading && !withHmr) return null;
if (!withLoading && !withHmr) {
return null;
}

return Template.asString([
`var createStylesheet = ${runtimeTemplate.basicFunction(
'chunkId, fullhref, resolve, reject',
[
'var linkTag = document.createElement("link");',
this.runtimeOptions.attributes,
this.runtimeOptions.attributes
? Template.asString(
Object.entries(this.runtimeOptions.attributes).map((entry) => {
const [key, value] = entry;

return `linkTag.setAttribute(${JSON.stringify(
key
)}, ${JSON.stringify(value)});`;
})
)
: '',
'linkTag.rel = "stylesheet";',
this.runtimeOptions.linkType
? `linkTag.type = ${JSON.stringify(this.runtimeOptions.linkType)};`
Expand Down
45 changes: 20 additions & 25 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,21 @@ class MiniCssExtractPlugin {
])
: Template.asString(['document.head.appendChild(linkTag);']);

const attributes =
typeof options.attributes === 'object' ? options.attributes : {};

// Todo in next major release set default to "false"
const linkType =
options.linkType === true || typeof options.linkType === 'undefined'
? 'text/css'
: options.linkType;

this.options = Object.assign(
{
filename: DEFAULT_FILENAME,
ignoreOrder: false,
},
{ filename: DEFAULT_FILENAME, ignoreOrder: false },
options
);

this.runtimeOptions = {
insert,
linkType,
linkType:
// Todo in next major release set default to "false"
options.linkType === true || typeof options.linkType === 'undefined'
? 'text/css'
: options.linkType,
attributes: options.attributes,
};

this.runtimeOptions.attributes = Template.asString(
Object.entries(attributes).map((entry) => {
const [key, value] = entry;

return `linkTag.setAttribute(${JSON.stringify(key)}, ${JSON.stringify(
value
)});`;
})
);

if (!this.options.chunkFilename) {
const { filename } = this.options;

Expand Down Expand Up @@ -426,7 +409,19 @@ class MiniCssExtractPlugin {
]),
'}',
'var linkTag = document.createElement("link");',
this.runtimeOptions.attributes,
this.runtimeOptions.attributes
? Template.asString(
Object.entries(this.runtimeOptions.attributes).map(
(entry) => {
const [key, value] = entry;

return `linkTag.setAttribute(${JSON.stringify(
key
)}, ${JSON.stringify(value)});`;
}
)
)
: '',
'linkTag.rel = "stylesheet";',
this.runtimeOptions.linkType
? `linkTag.type = ${JSON.stringify(
Expand Down