Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/angular/build/src/builders/dev-server/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ export async function* serveWithVite(
browserOptions.forceI18nFlatOutput = true;
}

const { vendor: thirdPartySourcemaps, scripts: scriptsSourcemaps } = normalizeSourceMaps(
browserOptions.sourceMap ?? false,
);
const {
vendor: thirdPartySourcemaps,
scripts: scriptsSourcemaps,
styles: stylesSourcemaps,
} = normalizeSourceMaps(browserOptions.sourceMap ?? false);

if (scriptsSourcemaps && browserOptions.server) {
// https://un5zrke0g2qx6zm5.julianrbryant.com/api/process.html#processsetsourcemapsenabledval
Expand Down Expand Up @@ -184,7 +186,7 @@ export async function* serveWithVite(
// Always enable JIT linking to support applications built with and without AOT.
// 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 },

1,
);

Expand Down Expand Up @@ -428,6 +430,7 @@ export async function* serveWithVite(
extensions?.middleware,
transformers?.indexHtml,
thirdPartySourcemaps,
stylesSourcemaps,
);

server = await createServer(serverConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export async function setupServer(
extensionMiddleware?: Connect.NextHandleFunction[],
indexHtmlTransformer?: (content: string) => Promise<string>,
thirdPartySourcemaps = false,
stylesSourcemaps = true,
): Promise<InlineConfig> {
const { normalizePath } = await import('vite');

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