Skip to content

Commit 881095e

Browse files
committedJan 7, 2025·
fix(@angular/build): enable serving files with bundle-like names
Ensure files with names resembling bundles, such as `main.js`, can be served correctly. This resolves issues where specific filenames were mistakenly treated as generated bundles, preventing them from being accessed directly. Closes #29232 (cherry picked from commit ef3dc2e)
1 parent 1189938 commit 881095e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎packages/angular/build/src/builders/dev-server/tests/behavior/build-assets_spec.ts

+21
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,26 @@ describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupT
141141
expect(await response?.status).toBe(301);
142142
expect(await response?.headers.get('Location')).toBe('/login/');
143143
});
144+
145+
it('serves a JavaScript asset named as a bundle', async () => {
146+
await harness.writeFile('public/test/main.js', javascriptFileContent);
147+
148+
setupTarget(harness, {
149+
assets: [
150+
{
151+
glob: '**/*',
152+
input: 'public',
153+
},
154+
],
155+
});
156+
157+
harness.useTarget('serve', {
158+
...BASE_OPTIONS,
159+
});
160+
161+
const { result, response } = await executeOnceAndFetch(harness, 'test/main.js');
162+
expect(result?.success).toBeTrue();
163+
expect(await response?.text()).toContain(javascriptFileContent);
164+
});
144165
});
145166
});

‎packages/angular/build/src/tools/vite/plugins/angular-memory-plugin.ts

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface AngularMemoryPluginOptions {
2222
}
2323

2424
const ANGULAR_PREFIX = '/@ng/';
25+
const VITE_FS_PREFIX = '/@fs/';
2526

2627
export async function createAngularMemoryPlugin(
2728
options: AngularMemoryPluginOptions,
@@ -34,6 +35,10 @@ export async function createAngularMemoryPlugin(
3435
// Ensures plugin hooks run before built-in Vite hooks
3536
enforce: 'pre',
3637
async resolveId(source, importer, { ssr }) {
38+
if (source.startsWith(VITE_FS_PREFIX)) {
39+
return;
40+
}
41+
3742
// For SSR with component HMR, pass through as a virtual module
3843
if (ssr && source.startsWith(ANGULAR_PREFIX)) {
3944
return '\0' + source;

0 commit comments

Comments
 (0)
Please sign in to comment.