fix(css): add processContent hook and async code generation support#20736
fix(css): add processContent hook and async code generation support#20736xiaoxiaojx wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: ba3f97c 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 (ba3f97c). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@ba3f97c
yarn add -D webpack@https://pkg.pr.new/webpack@ba3f97c
pnpm add -D webpack@https://pkg.pr.new/webpack@ba3f97c |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #20736 +/- ##
=======================================
Coverage 91.42% 91.42%
=======================================
Files 559 559
Lines 55091 55161 +70
Branches 14528 14546 +18
=======================================
+ Hits 50368 50432 +64
- Misses 4723 4729 +6
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:
|
alexander-akait
left a comment
There was a problem hiding this comment.
Looks good, I want to make a new release 31 or 1, let's merge it after this
11c12b8 to
e27b33b
Compare
Types CoverageCoverage after merging feat/process-content-hook into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| afterCodeGeneration: new SyncHook([]), | ||
|
|
||
| /** @type {AsyncSeriesWaterfallHook<[ProcessContentSource, string]>} */ | ||
| processContent: new AsyncSeriesWaterfallHook(["source", "name"]), |
There was a problem hiding this comment.
I looked deeply on this PR and I think we need to make improvements:
- Let's split this PRs into multiple -
processContent(maybe even codeGeneration name hook to align naming everywhere) hook and then make code generation async (we will merge them in one release, so we will not have problems here), for better history and review - I think we should run
processContenton compilation level (i.e. insideCompilation.js), not only for CSS modules, why?processContentcan be useful not only for CSS modules, also we can use it for HTML modules (future support) in JS, also it can be useful for asset modules too - compress images before insert them as base64/bytes and more, so for me we should have this hook for any types code generations
Summary
webpack/css-minimizer-webpack-plugin#311 Add compilation.hooks.processContent AsyncSeriesWaterfallHook for plugins to transform module content (e.g., CSS minimization) during code generation. The hook uses a pure functional waterfall design — plugins receive
[content, sourceMap]and return a new tuple, avoiding in-place mutation. Designed as async to support minimizers that leverageworker threadsfor parallel processing.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