Skip to content

🗜️ perf(build): optimize SWC minifier with translation-safe compression - #3133

Open
b-l-i-n-d wants to merge 1 commit into
build/dependenciesfrom
build/minifier-compression
Open

b-l-i-n-d wants to merge 1 commit into
build/dependenciesfrom
build/minifier-compression

Conversation

@b-l-i-n-d

@b-l-i-n-d b-l-i-n-d commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

ClickUp ticket link: https://app.clickup.com/t/9018365849/z8zyy1prfm

Description

This PR forms Layer 2 of the build stack. It enables SWC minifier compression passes while ensuring 100% compatibility with WordPress's internationalization and translation system.

How WordPress Handles Translations & Why This Solution Does Not Break

  • How translate.wordpress.org works: WordPress.org (GlotPress) scans shipped plugin files using WP-CLI's wp i18n make-pot to build official translation catalogs (see WordPress Internationalization Handbook). Its AST parser expects translation functions (__, _x, _n, etc.) to receive static string literals.
  • The minifier issue: Default minifier compression (conditionals: true) merges ternary expressions calling the same function:
    // Original:
    cond ? __("Active", "tutor") : __("Inactive", "tutor");
    // Default minifier merges to:
    __(cond ? "Active" : "Inactive", "tutor");
    Because the argument becomes a dynamic expression (cond ? ...), the WordPress parser cannot statically extract either string, dropping them from translate.wordpress.org.
  • Why our solution does not break: Setting compress: { conditionals: false } prevents the minifier from merging conditional branches into dynamic arguments, keeping literal string calls completely intact for GlotPress. All other compression passes (dead-code elimination, tree-shaking, scope flattening) remain fully active, maintaining maximum bundle reduction.

Key Changes

  • Minifier Optimization: Configured SWC minifier with compress: { conditionals: false }, reserved ['__', '_x', '_n', '_nx'], and preserved translator comments (format: { comments: /translators/i }).

Minifier Compression Stats (Before vs After)

Bundle Entrypoint Uncompressed (compress: false) Optimized Minifier (conditionals: false) Net Reduction
tutor-course-builder.js 1,030 KiB 759 KiB -271 KiB (-26.3%)
tutor-order-details.js 668 KiB 506 KiB -162 KiB (-24.3%)
tutor-payment-settings.js 780 KiB 598 KiB -182 KiB (-23.3%)
tutor-tax-settings.js 695 KiB 525 KiB -170 KiB (-24.5%)
tutor-import-export.js 727 KiB 546 KiB -181 KiB (-24.9%)
tutor-coupon.js 545 KiB 441 KiB -104 KiB (-19.1%)
tutor-addon-list.js 494 KiB 356 KiB -138 KiB (-27.9%)
tutor-core.js 219 KiB 190 KiB -29 KiB (-13.2%)
tutor.js 135 KiB 108 KiB -27 KiB (-20.0%)

Stack

  1. 📦 build(deps): update project dependencies and ESLint 10 configuration #3132 (Dependency) build/dependencies -> dev
  2. # (Compress) build/minifier-compression -> build/dependencies
  3. ⚡ feat(build): Add React Compiler support and optimize component rendering #3131 (Compiler) react-compiler -> build/minifier-compression

Testing

  • Tested
  • Not tested
  • Build verification: rspack --mode=production runs cleanly.
  • Translation safety verification: Executed full plugin string extraction via wp i18n make-pot, successfully verifying all 3,538 strings (including 1,451 from built JS bundles) are parsed and extracted cleanly without skipped expressions.

Use of AI Tool

Used: Yes

Used for:

Benchmarking SWC minifier compression passes and verifying translation string extraction via wp i18n make-pot.

@b-l-i-n-d
b-l-i-n-d added this pull request to stack #3134 October 27, 2026 16:39
@b-l-i-n-d b-l-i-n-d changed the title perf(build): optimize SWC minifier with translation-safe compression 🗜️ perf(build): optimize SWC minifier with translation-safe compression Oct 27, 2026
@b-l-i-n-d
b-l-i-n-d force-pushed the build/minifier-compression branch from 4c92827 to 3ce05e4 Compare October 27, 2026 17:14
@b-l-i-n-d b-l-i-n-d self-assigned this Oct 28, 2026
@b-l-i-n-d b-l-i-n-d added enhancement New feature or request QoL Quality of Life labels Oct 28, 2026
@b-l-i-n-d
b-l-i-n-d marked this pull request as ready for review October 28, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request QoL Quality of Life

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant