Skip to content

fix(@angular/build): respect sourceMap configuration in dev server#32941

Open
maruthang wants to merge 1 commit intoangular:mainfrom
maruthang:fix-31331-sourcemap-config
Open

fix(@angular/build): respect sourceMap configuration in dev server#32941
maruthang wants to merge 1 commit intoangular:mainfrom
maruthang:fix-31331-sourcemap-config

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

@maruthang maruthang commented Apr 6, 2026

Summary

  • The dev server was ignoring the sourceMap configuration from angular.json, always injecting inline source maps into all served files even when explicitly disabled
  • css.devSourcemap was hardcoded to true instead of using the styles source map setting
  • The prebundle JavaScriptTransformer was created with sourcemap: true hardcoded, causing Vite's dependency prebundling to always generate source maps for third-party packages
  • The fix passes the normalized scripts and styles source map settings through to the Vite configuration

Closes #31331

Test plan

  • Run ng serve with "sourceMap": false in angular.json and verify no inline source maps in served JS/CSS files
  • Run ng serve with default config and verify source maps still work
  • Run ng serve with granular config {"scripts": false, "styles": true} and verify only CSS has source maps

The dev server was ignoring the `sourceMap` configuration from angular.json,
always injecting inline source maps into all served files. This affected both
CSS (hardcoded `devSourcemap: true`) and JavaScript (prebundle transformer
hardcoded `sourcemap: true`), causing 2-3x file size inflation even when
source maps were explicitly disabled.

The fix passes the normalized `scripts` and `styles` source map settings
through to the Vite configuration, so that `css.devSourcemap` and the
prebundle transformer respect the user's `sourceMap` setting.

Closes angular#31331
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the Vite dev server by implementing granular source map controls, specifically adding support for style source maps and replacing hardcoded values with configuration-driven settings. A review comment identifies that the prebundleTransformer should utilize thirdPartySourcemaps rather than scriptsSourcemaps to ensure that third-party dependency source maps are only generated when explicitly configured.

// In a development environment the additional scope information does not
// have a negative effect unlike production where final output size is relevant.
{ sourcemap: true, jit: true, thirdPartySourcemaps },
{ sourcemap: scriptsSourcemaps, jit: true, thirdPartySourcemaps },
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The prebundleTransformer is used specifically for third-party dependencies during the Vite prebundling process. It should therefore respect the thirdPartySourcemaps (which corresponds to the vendor source map setting) rather than scriptsSourcemaps for its internal sourcemap generation toggle.

Using scriptsSourcemaps here means that if a user has "sourceMap": true (which defaults vendor to false in Angular), source maps will still be generated for prebundled third-party packages, which contradicts the configuration and the stated goal of this PR to avoid injecting source maps when disabled.

Suggested change
{ sourcemap: scriptsSourcemaps, jit: true, thirdPartySourcemaps },
{ sourcemap: thirdPartySourcemaps, jit: true, thirdPartySourcemaps },

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.

ng serve with esbuild/Vite ignores sourceMap configuration, injecting large inline source maps into all files

1 participant