Skip to content

Commit 944e964

Browse files
committed
fix(@angular-devkit/build-angular): only include vendor sourcemaps when using the dev-server when the option is enabled
Prior to this change the vendor sourcemaps option was not being considered when in the vite JavaScript transformation pipeline.
1 parent 3c66ba7 commit 944e964

File tree

1 file changed

+13
-2
lines changed
  • packages/angular_devkit/build_angular/src/builders/dev-server

1 file changed

+13
-2
lines changed

packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { JavaScriptTransformer } from '../../tools/esbuild/javascript-transforme
2222
import { createRxjsEsmResolutionPlugin } from '../../tools/esbuild/rxjs-esm-resolution-plugin';
2323
import { getFeatureSupport, transformSupportedBrowsersToTargets } from '../../tools/esbuild/utils';
2424
import { createAngularLocaleDataPlugin } from '../../tools/vite/i18n-locale-plugin';
25+
import { normalizeSourceMaps } from '../../utils';
2526
import { loadEsmModule } from '../../utils/load-esm';
2627
import { renderPage } from '../../utils/server-rendering/render-page';
2728
import { getSupportedBrowsers } from '../../utils/supported-browsers';
@@ -104,12 +105,14 @@ export async function* serveWithVite(
104105
browserOptions.forceI18nFlatOutput = true;
105106
}
106107

108+
const { vendor: thirdPartySourcemaps } = normalizeSourceMaps(browserOptions.sourceMap ?? false);
109+
107110
// Setup the prebundling transformer that will be shared across Vite prebundling requests
108111
const prebundleTransformer = new JavaScriptTransformer(
109112
// Always enable JIT linking to support applications built with and without AOT.
110113
// In a development environment the additional scope information does not
111114
// have a negative effect unlike production where final output size is relevant.
112-
{ sourcemap: true, jit: true, thirdPartySourcemaps: true },
115+
{ sourcemap: true, jit: true, thirdPartySourcemaps },
113116
1,
114117
true,
115118
);
@@ -237,6 +240,7 @@ export async function* serveWithVite(
237240
browserOptions.loader as EsbuildLoaderOption | undefined,
238241
extensions?.middleware,
239242
transformers?.indexHtml,
243+
thirdPartySourcemaps,
240244
);
241245

242246
server = await createServer(serverConfiguration);
@@ -405,6 +409,7 @@ export async function setupServer(
405409
prebundleLoaderExtensions: EsbuildLoaderOption | undefined,
406410
extensionMiddleware?: Connect.NextHandleFunction[],
407411
indexHtmlTransformer?: (content: string) => Promise<string>,
412+
thirdPartySourcemaps = false,
408413
): Promise<InlineConfig> {
409414
const proxy = await loadProxyConfiguration(
410415
serverOptions.workspaceRoot,
@@ -484,6 +489,7 @@ export async function setupServer(
484489
prebundleTransformer,
485490
target,
486491
loader: prebundleLoaderExtensions,
492+
thirdPartySourcemaps,
487493
}),
488494
},
489495
plugins: [
@@ -740,6 +746,7 @@ export async function setupServer(
740746
prebundleTransformer,
741747
target,
742748
loader: prebundleLoaderExtensions,
749+
thirdPartySourcemaps,
743750
}),
744751
};
745752

@@ -810,6 +817,7 @@ function getDepOptimizationConfig({
810817
prebundleTransformer,
811818
ssr,
812819
loader,
820+
thirdPartySourcemaps,
813821
}: {
814822
disabled: boolean;
815823
exclude: string[];
@@ -818,10 +826,13 @@ function getDepOptimizationConfig({
818826
prebundleTransformer: JavaScriptTransformer;
819827
ssr: boolean;
820828
loader?: EsbuildLoaderOption;
829+
thirdPartySourcemaps: boolean;
821830
}): DepOptimizationConfig {
822831
const plugins: ViteEsBuildPlugin[] = [
823832
{
824-
name: `angular-vite-optimize-deps${ssr ? '-ssr' : ''}`,
833+
name: `angular-vite-optimize-deps${ssr ? '-ssr' : ''}${
834+
thirdPartySourcemaps ? '-vendor-sourcemap' : ''
835+
}`,
825836
setup(build) {
826837
build.onLoad({ filter: /\.[cm]?js$/ }, async (args) => {
827838
return {

0 commit comments

Comments
 (0)