Skip to content

Commit c7eb5e7

Browse files
committed
fix(@angular/build): respect sourceMap configuration in dev server
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 #31331
1 parent 7fbc715 commit c7eb5e7

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

packages/angular/build/src/builders/dev-server/vite/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ export async function* serveWithVite(
146146
browserOptions.forceI18nFlatOutput = true;
147147
}
148148

149-
const { vendor: thirdPartySourcemaps, scripts: scriptsSourcemaps } = normalizeSourceMaps(
150-
browserOptions.sourceMap ?? false,
151-
);
149+
const {
150+
vendor: thirdPartySourcemaps,
151+
scripts: scriptsSourcemaps,
152+
styles: stylesSourcemaps,
153+
} = normalizeSourceMaps(browserOptions.sourceMap ?? false);
152154

153155
if (scriptsSourcemaps && browserOptions.server) {
154156
// https://nodejs.org/api/process.html#processsetsourcemapsenabledval
@@ -184,7 +186,7 @@ export async function* serveWithVite(
184186
// Always enable JIT linking to support applications built with and without AOT.
185187
// In a development environment the additional scope information does not
186188
// have a negative effect unlike production where final output size is relevant.
187-
{ sourcemap: true, jit: true, thirdPartySourcemaps },
189+
{ sourcemap: scriptsSourcemaps, jit: true, thirdPartySourcemaps },
188190
1,
189191
);
190192

@@ -428,6 +430,7 @@ export async function* serveWithVite(
428430
extensions?.middleware,
429431
transformers?.indexHtml,
430432
thirdPartySourcemaps,
433+
stylesSourcemaps,
431434
);
432435

433436
server = await createServer(serverConfiguration);

packages/angular/build/src/builders/dev-server/vite/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export async function setupServer(
145145
extensionMiddleware?: Connect.NextHandleFunction[],
146146
indexHtmlTransformer?: (content: string) => Promise<string>,
147147
thirdPartySourcemaps = false,
148+
stylesSourcemaps = true,
148149
): Promise<InlineConfig> {
149150
const { normalizePath } = await import('vite');
150151

@@ -175,7 +176,7 @@ export async function setupServer(
175176
// We use custom as we do not rely on Vite's htmlFallbackMiddleware and indexHtmlMiddleware.
176177
appType: 'custom',
177178
css: {
178-
devSourcemap: true,
179+
devSourcemap: stylesSourcemaps,
179180
},
180181
// Ensure custom 'file' loader build option entries are handled by Vite in application code that
181182
// reference third-party libraries. Relative usage is handled directly by the build and not Vite.

0 commit comments

Comments
 (0)