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, }; }