Skip to content

Commit d2bd7f6

Browse files
committed
refactor(@angular/build): remove advanced chunking option in experimental chunk optimizer
Removes the experimental `advancedChunks` configuration from the Rolldown-based chunk optimizer. This experimental feature is being temporarily removed to allow for further refinement and testing of the chunking strategy. A new E2E test (`chunk-optimizer-lazy`) has been added to validate the default chunking behavior with multiple lazy-loaded routes, ensuring that the optimizer still produces a reasonable number of output files without the advanced configuration.
1 parent 50072cd commit d2bd7f6

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

packages/angular/build/src/builders/application/chunk-optimizer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ export async function optimizeChunks(
253253

254254
const result = await bundle.generate({
255255
minify: { mangle: false, compress: false },
256-
advancedChunks: { minSize: 8192 },
257256
sourcemap,
258257
chunkFileNames: (chunkInfo) => `${chunkInfo.name.replace(/-[a-zA-Z0-9]{8}$/, '')}-[hash].js`,
259258
});

tests/legacy-cli/e2e.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ WEBPACK_IGNORE_TESTS = [
5656
"tests/build/auto-csp*",
5757
"tests/build/incremental-watch.js",
5858
"tests/build/chunk-optimizer.js",
59+
"tests/build/chunk-optimizer-lazy.js",
5960
]
6061

6162
def _to_glob(patterns):
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import assert from 'node:assert/strict';
2+
import { readdir } from 'node:fs/promises';
3+
import { replaceInFile } from '../../utils/fs';
4+
import { execWithEnv, ng } from '../../utils/process';
5+
6+
export default async function () {
7+
// Add lazy routes.
8+
await ng('generate', 'component', 'lazy-a');
9+
await ng('generate', 'component', 'lazy-b');
10+
await ng('generate', 'component', 'lazy-c');
11+
await replaceInFile(
12+
'src/app/app.routes.ts',
13+
'routes: Routes = [];',
14+
`routes: Routes = [
15+
{
16+
path: 'lazy-a',
17+
loadComponent: () => import('./lazy-a/lazy-a').then(m => m.LazyA),
18+
},
19+
{
20+
path: 'lazy-b',
21+
loadComponent: () => import('./lazy-b/lazy-b').then(m => m.LazyB),
22+
},
23+
{
24+
path: 'lazy-c',
25+
loadComponent: () => import('./lazy-c/lazy-c').then(m => m.LazyC),
26+
},
27+
];`,
28+
);
29+
30+
// Build without chunk optimization
31+
await ng('build', '--output-hashing=none');
32+
const unoptimizedFiles = await readdir('dist/test-project/browser');
33+
const unoptimizedJsFiles = unoptimizedFiles.filter((f) => f.endsWith('.js'));
34+
35+
// Build with chunk optimization
36+
await execWithEnv('ng', ['build', '--output-hashing=none'], {
37+
...process.env,
38+
NG_BUILD_OPTIMIZE_CHUNKS: '1',
39+
});
40+
const optimizedFiles = await readdir('dist/test-project/browser');
41+
const optimizedJsFiles = optimizedFiles.filter((f) => f.endsWith('.js'));
42+
43+
// Check that the number of chunks is reduced but not all combined
44+
assert.ok(
45+
optimizedJsFiles.length < unoptimizedJsFiles.length,
46+
`Expected chunk count to be less than ${unoptimizedJsFiles.length}, but was ${optimizedJsFiles.length}.`,
47+
);
48+
assert.ok(
49+
optimizedJsFiles.length > 1,
50+
`Expected more than one chunk, but found ${optimizedJsFiles.length}.`,
51+
);
52+
}

0 commit comments

Comments
 (0)