fix: support CSS text/css-style-sheet exportType module concatenation#20851
Conversation
🦋 Changeset detectedLatest commit: 4369850 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is packaged and the instant preview is available (3374804). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@3374804
yarn add -D webpack@https://pkg.pr.new/webpack@3374804
pnpm add -D webpack@https://pkg.pr.new/webpack@3374804 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #20851 +/- ##
==========================================
+ Coverage 91.32% 91.35% +0.03%
==========================================
Files 562 562
Lines 55661 55736 +75
Branches 14719 14764 +45
==========================================
+ Hits 50831 50920 +89
+ Misses 4830 4816 -14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| const moduleId = generateContext.chunkGraph.getModuleId(module); | ||
| const moduleId = | ||
| generateContext.chunkGraph.getModuleId(module) || | ||
| module.identifier(); |
There was a problem hiding this comment.
Maybe always use module.identifier()? Sounds like it will work without any problems, also we need to check do we need escape them to avoid weird characters in JS code
There was a problem hiding this comment.
the identifier is already passed through JSON.stringify(), so special characters in the path are properly escaped in the JS output.
| /** | ||
| * @returns {boolean} true | ||
| */ | ||
| get supportsConcatenation() { |
There was a problem hiding this comment.
I like this improvement, no more hard-coded code, but let's make this as a Function, I am afraid in future when we will concat non JS modules with JS modules we can have more complex cases (where we need to pass module graph or maybe more)
alexander-akait
left a comment
There was a problem hiding this comment.
Looks very good, let's make some improvements above, thanks
1d9cb7b to
d30532a
Compare
alexander-akait
left a comment
There was a problem hiding this comment.
Looks good, the only thing I am afraid supportsConcatenation is a new method, so if someone use custom Dependency implement (or using old version of webpack, where we don't have) we will fail here, make sense to add typeof check with TODO about removing this check in webpack@6 and we can merge
d30532a to
2400723
Compare
| if (concatId !== null) { | ||
| chunkGraph.setModuleId(this.rootModule, concatId); | ||
| } | ||
| } |
There was a problem hiding this comment.
I am afraid it will be a breaking change and potential module overlapping, we need to think how to fix it without it
2400723 to
0247fa5
Compare
21fcc44 to
60c4ca3
Compare
|
Sorry for the delay — @alexander-akait, thanks for the great review and suggestions. |
a5831dd to
a5720d6
Compare
0872686 to
f1aee50
Compare
f1aee50 to
7ab61de
Compare
Types CoverageCoverage after merging fix/css-text-css-style-sheet-concatenation into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
…107) (#8244) Webpack 5.107 brings two additions to the experiments.css feature set: - Scope hoisting (module concatenation) now applies to CSS Modules with exportType "text", "css-style-sheet", "style", or "link", reducing runtime overhead in CSS-heavy bundles when optimization.concatenateModules is enabled. - @value identifiers can be used as the path argument to @import and inside url() references, so shared paths/assets are defined once and reused. Both quoted and bare forms are accepted and resolved through webpack's normal asset pipeline. Adds two bullets to the existing experimental features list in experiments.css. Refs: - webpack/webpack#20851 (scope hoisting) - webpack/webpack#20925 (@value in URLs)
Summary
Rename export-type-text-concatenation to export-type-concatenation and add test cases for all CSS exportTypes: text, css-style-sheet, style, and link (CSS modules). Each type verifies its specific output format (string, CSSStyleSheet, <style> injection, class name export) while all modules are concatenated into a single ConcatenatedModule.
What kind of change does this PR introduce?
fix
Did you add tests for your changes?
Yes
Does this PR introduce a breaking change?
No
If relevant, what needs to be documented once your changes are merged or what have you already documented?
Nothing
Use of AI
Partial