Skip to content

feat: load minimizers by module path in workers - #732

Closed
xiaoxiaojx wants to merge 4 commits into
mainfrom
feat/worker-implementation-path
Closed

xiaoxiaojx wants to merge 4 commits into
mainfrom
feat/worker-implementation-path

Conversation

@xiaoxiaojx

@xiaoxiaojx xiaoxiaojx commented Sep 9, 2026

Copy link
Copy Markdown
Member

Summary

  • Allow minimizer.implementation as a module path string or { path, export } (sass-loader style). Default terser uses { path, export: "terserMinify" }.
  • When every implementation in a task (including embedded) is a path, workers require via minify instead of serialize-javascript + new Function (transform). Inline minify functions keep the legacy path.
  • Split helpers into implementation.js so the worker entry only exports minify / transform; unify loading through getMinimizerSlots / embeddedFromSlots.

Test plan

  • yarn test (full suite)
  • Confirm default parallel builds call worker.minify (not transform)
  • Confirm minify: () => … / mixed path+function configs fall back to transform
  • Smoke a yarn-linked webpack build / minimizer-handoff-unit bench against rebuilt dist

Made with Cursor

Summary by CodeRabbit

  • New Features

    • Minimizer implementations can now be specified as module paths or { path, export } objects.
    • Supports default exports, named exports, and CommonJS module exports.
    • Path-based implementations run more efficiently in worker threads without function serialization.
    • Inline functions remain supported, including mixed configurations and embedded minimizers.
  • Documentation

    • Updated configuration guidance and type definitions to describe module-based implementations and worker behavior.

@changeset-bot

changeset-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2575275

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
minimizer-webpack-plugin Minor

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

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.10714% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.78%. Comparing base (1cf49b0) to head (2575275).

Files with missing lines Patch % Lines
src/implementation.js 98.27% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #732      +/-   ##
==========================================
+ Coverage   97.75%   97.78%   +0.02%     
==========================================
  Files           4        5       +1     
  Lines        1557     1623      +66     
  Branches      588      617      +29     
==========================================
+ Hits         1522     1587      +65     
- Misses         35       36       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 9, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: xiaoxiaojx / name: xiaoxiaojx (e50aeee)

@xiaoxiaojx
xiaoxiaojx force-pushed the feat/worker-implementation-path branch from 6ad15aa to e50aeee Compare September 9, 2026 06:31
The default minimizer is named by module path, the minimizer loop reads the slots this branch introduced, and both hash guards ask the slots how many there are.
Plus the case the test plan left open: one function among several paths leaves the whole task on the source path.
@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: b9e823f5-fb06-4ef2-99cb-2f9663e51137

📥 Commits

Reviewing files that changed from the base of the PR and between 8cb5b9f and 2575275.

📒 Files selected for processing (5)
  • README.md
  • src/implementation.js
  • src/index.js
  • test/parallel-option.test.js
  • types/index.d.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • README.md
  • src/implementation.js
  • src/index.js
  • types/index.d.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.


Walkthrough

The plugin now accepts minimizer implementations as functions, module path strings, or { path, export } objects. Shared helpers normalize and load these implementations. The plugin stores configured values with loaded functions and uses worker.minify when all matched implementations and task values are module-path compatible. Tasks with inline functions continue to use transform. Schemas, type declarations, documentation, fixtures, and tests were updated.

Priority: ➖ Normal

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: loading minimizers by module path in workers.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 11 files. (1 skipped: 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/implementation.js

ESLint failed to execute (timeout).

src/index.js

ESLint skipped: the matched ESLint configuration already failed (timeout).

test/parallel-option.test.js

ESLint skipped: the matched ESLint configuration already failed (timeout).

  • 1 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 Major · Pass the loaded minimizer function to declaredStage(). · index.js:1920

src/index.js:1920
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Pass the loaded minimizer function to declaredStage(). A module path or { path, export } value does not expose the loaded function's getStage, so that minimizer uses defaultStage() instead of its declared stage. Use the corresponding loaded slot function while preserving the slot index for dispatch.

Proposed fix
   minimizersByStage(compiler) {
-    const { implementation } = this.options.minimizer;
-    const each = Array.isArray(implementation)
-      ? implementation
-      : [implementation];
+    const slots = this.getMinimizerSlots();
     const fallback = this.defaultStage(compiler);
     const byStage = new Map();

-    for (let i = 0; i < each.length; i++) {
-      const asked = declaredStage(compiler, each[i]);
+    for (let i = 0; i < slots.length; i++) {
+      const asked = declaredStage(compiler, slots[i].fn);

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 379b994c-fa58-470a-871e-7617fe8e2621

📥 Commits

Reviewing files that changed from the base of the PR and between 1cf49b0 and 8cb5b9f.

⛔ Files ignored due to path filters (2)
  • test/__snapshots__/parallel-option.test.js.snap is excluded by !**/*.snap
  • test/__snapshots__/validate-options.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (14)
  • .changeset/worker-implementation-path.md
  • README.md
  • src/implementation.js
  • src/index.js
  • src/minify.js
  • src/options.json
  • test/extractComments-option.test.js
  • test/fixtures/minify-default-export.js
  • test/fixtures/minify-default-property.js
  • test/implementation.test.js
  • test/parallel-option.test.js
  • types/implementation.d.ts
  • types/index.d.ts
  • types/minify.d.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.

Comment thread README.md Outdated
Comment thread test/extractComments-option.test.js
Comment thread types/index.d.ts
A required minimizer is handed the payload as it is, so an extractComments callback or a function in a minimizer's own options died as could not be cloned; generators stay callable-only, which is all the schema takes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants