Optimize webpack production builds and asset compilation - #1467
Open
drusepth wants to merge 1 commit into
Open
Conversation
Four separate sources of waste in `rails assets:precompile`, none of which were breaking anything, but all of which made the build slower and the output noisier than it needed to be. Sprockets was compiling every file twice. `manifest.js` had `link_directory` over app/assets/javascripts and app/assets/stylesheets, which emits a fingerprinted + gzipped standalone asset for each of the ~85 files in those directories. Those same files are all pulled into application.js/application.css by `require_tree .`, and no view links to any of them individually - a grep for `javascript_include_tag`/`stylesheet_link_tag`/`asset_path` across app/ and lib/ turns up only 'application' and 'thredded' (the latter still precompiled via config/initializers/assets.rb). Replaced the two directives with explicit links to the two manifests we actually serve. Webpack was building a pack nothing renders. `packs/server_rendering.js` exists for react-rails' `prerender: true`, and there are zero prerendered components in the codebase. It was costing 704 KiB of output, a 2.86 MiB source map, and a quarter of the build time on every deploy. Production source maps were being shipped and compressed. Webpacker defaults to `devtool: 'source-map'`, which annotates every bundle with a `sourceMappingURL` comment; with no browser-side Sentry SDK, the only consumers were visitors with devtools open pulling multi-megabyte maps. Switched to `hidden-source-map` so the maps still land in public/packs for manual debugging without being advertised, and dropped `.map` from both compression passes - those `.map.gz` and `.map.br` files accounted for 7 of the 14 entries in the asset size limit warning. Browser data was stale. Ran update-browserslist-db to bring caniuse-lite current (no target browser changes, so compiled output is unaffected) and added a resolution to dedupe baseline-browser-mapping, which two different transitive browserslist versions were pinning to old copies. Verified against a production webpack build: no `.map.gz`/`.map.br` emitted, no `sourceMappingURL` in the shipped bundles, no server_rendering entry, and both stale-data warnings gone. Same-machine before/after: public/packs 19M -> 12M, cold build 83s -> 45s, warm build ~28s -> ~21s. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0154QFGT71QHC6WCsjvdkyvJ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #
Changes proposed:
Webpack production optimizations: Added production-only configuration to use
hidden-source-mapinstead ofsource-mapfor devtool, preventing source maps from being downloaded by visitors while still enabling manual debugging. Updated compression plugins to exclude.mapfiles from gzip and brotli compression, significantly reducing asset size warnings during precompile.Asset manifest cleanup: Replaced generic
link_directorydirectives with explicitlinkentries for only the bundles actually referenced from layouts (application.jsandapplication.css). This eliminates redundant compilation of ~85 files as standalone fingerprinted assets that no view links to, improving build performance.Removed unused server-side rendering pack: Deleted
app/javascript/packs/server_rendering.jswhich is no longer needed.Dependency resolution: Added
baseline-browser-mappingto yarn resolutions to ensure consistent dependency versions.@indentlabs/contributors
https://claude.ai/code/session_0154QFGT71QHC6WCsjvdkyvJ