Skip to content

Optimize webpack production builds and asset compilation - #1467

Open
drusepth wants to merge 1 commit into
tailwind-redesignfrom
claude/asset-precompile-warnings-hbyu1s
Open

Optimize webpack production builds and asset compilation#1467
drusepth wants to merge 1 commit into
tailwind-redesignfrom
claude/asset-precompile-warnings-hbyu1s

Conversation

@drusepth

Copy link
Copy Markdown
Member

Fixes #

Changes proposed:

  • Webpack production optimizations: Added production-only configuration to use hidden-source-map instead of source-map for devtool, preventing source maps from being downloaded by visitors while still enabling manual debugging. Updated compression plugins to exclude .map files from gzip and brotli compression, significantly reducing asset size warnings during precompile.

  • Asset manifest cleanup: Replaced generic link_directory directives with explicit link entries for only the bundles actually referenced from layouts (application.js and application.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.js which is no longer needed.

  • Dependency resolution: Added baseline-browser-mapping to yarn resolutions to ensure consistent dependency versions.

@indentlabs/contributors

https://claude.ai/code/session_0154QFGT71QHC6WCsjvdkyvJ

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
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