Skip to content

wp-build-polyfills: strip minified sourcemaps from production builds#50734

Draft
louwie17 wants to merge 1 commit into
trunkfrom
update/wp-build-polyfills-strip-min-sourcemaps
Draft

wp-build-polyfills: strip minified sourcemaps from production builds#50734
louwie17 wants to merge 1 commit into
trunkfrom
update/wp-build-polyfills-strip-min-sourcemaps

Conversation

@louwie17

@louwie17 louwie17 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Not sure if we will go ahead with this yet, as it would mean that SCRIPT_DEBUG=true is of no use

Proposed changes

@wordpress/build (wp-build) hardcodes sourcemap: true for package bundles, so every production build emits *.min.js.map files under build/modules/** and build/scripts/**. Since the whole build/** tree is production-include, those maps ship to the package mirror and into consumer plugin zips — ~11 MiB for Premium Analytics today (e.g. build/modules/ui/index.min.js.map alone is 3.2 MiB). Widget and route bundles get no sourcemaps at all, so the maps that do ship are inconsistent dead weight. (No upstream toggle exists yet; nearest analogs are WordPress/gutenberg#75395 and WordPress/gutenberg#75993.)

  • Extend strip-unminified-prod in wp-build-polyfills to also delete *.min.js.map / *.min.css.map under its target subdirs (routes, scripts, modules, styles, widgets).
  • Strip the trailing sourceMappingURL comment from each minified asset whose map was deleted, so browsers don't request a 404'd map.
  • Report the removed sourcemap count in the bin's summary line and in strip()'s return value (deletedMaps).
  • Extend the end-to-end test (real wp-build output) to assert maps are deleted and asset references stripped, and that the pass stays idempotent.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

  • cd projects/packages/wp-build-polyfills && pnpm run build && pnpm run test — all tests pass, including strip-unminified-prod-real-fixture.test.js which builds a real wp-build fixture and asserts the .min.js.map files are removed and their sourceMappingURL references stripped.
  • For an end-to-end check: cd projects/packages/premium-analytics && pnpm run build-production, then confirm find build -name '*.map' returns nothing and grep -r sourceMappingURL build --include='*.min.js' finds no references (the summary line reports removed ... 8 minified sourcemap(s)).
  • Confirm the dashboard still loads normally from such a build (loaders collapse to .min.js as before; only the map files and their references are gone).

wp-build hardcodes sourcemap: true for package bundles (build/modules/**
and build/scripts/**), so *.min.js.map files (~11 MiB for Premium
Analytics) shipped to every production mirror via the build/**
production-include. Extend strip-unminified-prod to delete
*.min.js.map / *.min.css.map under its target subdirs and strip the
trailing sourceMappingURL comment from each minified asset so browsers
don't request the deleted map.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QCScbQabawavV9iSNFpZhE
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the update/wp-build-polyfills-strip-min-sourcemaps branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/wp-build-polyfills-strip-min-sourcemaps
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/wp-build-polyfills-strip-min-sourcemaps

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/wp-build-polyfills/bin/strip-unminified-prod-lib.js 251/266 (94.36%) 1.18% 0 💚

Full summary · PHP report · JS report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant