Skip to content

Commit 0760143

Browse files
committed
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
1 parent f1ed025 commit 0760143

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

packages/angular/build/src/builders/application/tests/options/deploy-url_spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,33 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
5858
);
5959
});
6060

61+
it('should prepend deploy URL to file loader import URLs', async () => {
62+
await harness.writeFile(
63+
'./src/types.d.ts',
64+
'declare module "*.svg" { const url: string; export default url; }',
65+
);
66+
await harness.writeFile('./src/app/test.svg', '<svg></svg>');
67+
await harness.writeFile(
68+
'src/main.ts',
69+
`import svgUrl from './app/test.svg';\nconsole.log(svgUrl);`,
70+
);
71+
72+
harness.useTarget('build', {
73+
...BASE_OPTIONS,
74+
loader: {
75+
'.svg': 'file',
76+
},
77+
deployUrl: 'https://example.com/some/path/',
78+
});
79+
80+
const { result } = await harness.executeOnce();
81+
expect(result?.success).toBeTrue();
82+
83+
harness
84+
.expectFile('dist/browser/main.js')
85+
.content.toContain('https://example.com/some/path/media/test.svg');
86+
});
87+
6188
it('should update resources component stylesheets to reference deployURL', async () => {
6289
await harness.writeFile('src/app/test.svg', '<svg></svg>');
6390
await harness.writeFile(

packages/angular/build/src/tools/esbuild/application-code-bundle.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ function getEsBuildCommonOptions(options: NormalizedApplicationBuildOptions): Bu
550550
i18nOptions,
551551
customConditions,
552552
frameworkVersion,
553+
publicPath,
553554
} = options;
554555

555556
// Ensure unique hashes for i18n translation changes when using post-process inlining.
@@ -654,6 +655,7 @@ function getEsBuildCommonOptions(options: NormalizedApplicationBuildOptions): Bu
654655
},
655656
loader: loaderExtensions,
656657
footer,
658+
publicPath,
657659
plugins,
658660
};
659661
}

0 commit comments

Comments
 (0)