From 076014369e52cab4d217c0b1652deff719e99d45 Mon Sep 17 00:00:00 2001 From: Maruthan G Date: Fri, 27 Mar 2026 15:21:40 +0530 Subject: [PATCH] fix(@angular/build): prepend deploy-url to file loader output paths Pass the publicPath option through to esbuild's common options so that assets processed by the file loader (e.g., SVGs imported via URL) get the deploy-url prefix applied, matching the previous webpack behavior. Fixes #32789 --- .../tests/options/deploy-url_spec.ts | 27 +++++++++++++++++++ .../tools/esbuild/application-code-bundle.ts | 2 ++ 2 files changed, 29 insertions(+) diff --git a/packages/angular/build/src/builders/application/tests/options/deploy-url_spec.ts b/packages/angular/build/src/builders/application/tests/options/deploy-url_spec.ts index a03ca2b026e7..8ae1b37c94c8 100644 --- a/packages/angular/build/src/builders/application/tests/options/deploy-url_spec.ts +++ b/packages/angular/build/src/builders/application/tests/options/deploy-url_spec.ts @@ -58,6 +58,33 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { ); }); + it('should prepend deploy URL to file loader import URLs', async () => { + await harness.writeFile( + './src/types.d.ts', + 'declare module "*.svg" { const url: string; export default url; }', + ); + await harness.writeFile('./src/app/test.svg', ''); + await harness.writeFile( + 'src/main.ts', + `import svgUrl from './app/test.svg';\nconsole.log(svgUrl);`, + ); + + harness.useTarget('build', { + ...BASE_OPTIONS, + loader: { + '.svg': 'file', + }, + deployUrl: 'https://example.com/some/path/', + }); + + const { result } = await harness.executeOnce(); + expect(result?.success).toBeTrue(); + + harness + .expectFile('dist/browser/main.js') + .content.toContain('https://example.com/some/path/media/test.svg'); + }); + it('should update resources component stylesheets to reference deployURL', async () => { await harness.writeFile('src/app/test.svg', ''); await harness.writeFile( diff --git a/packages/angular/build/src/tools/esbuild/application-code-bundle.ts b/packages/angular/build/src/tools/esbuild/application-code-bundle.ts index c3f542e1bdfb..b4ef09976ead 100644 --- a/packages/angular/build/src/tools/esbuild/application-code-bundle.ts +++ b/packages/angular/build/src/tools/esbuild/application-code-bundle.ts @@ -550,6 +550,7 @@ function getEsBuildCommonOptions(options: NormalizedApplicationBuildOptions): Bu i18nOptions, customConditions, frameworkVersion, + publicPath, } = options; // Ensure unique hashes for i18n translation changes when using post-process inlining. @@ -654,6 +655,7 @@ function getEsBuildCommonOptions(options: NormalizedApplicationBuildOptions): Bu }, loader: loaderExtensions, footer, + publicPath, plugins, }; }