Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ export async function optimizeChunks(

const result = await bundle.generate({
minify: { mangle: false, compress: false },
advancedChunks: { minSize: 8192 },
sourcemap,
chunkFileNames: (chunkInfo) => `${chunkInfo.name.replace(/-[a-zA-Z0-9]{8}$/, '')}-[hash].js`,
});
Expand Down
1 change: 1 addition & 0 deletions tests/legacy-cli/e2e.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ WEBPACK_IGNORE_TESTS = [
"tests/build/auto-csp*",
"tests/build/incremental-watch.js",
"tests/build/chunk-optimizer.js",
"tests/build/chunk-optimizer-lazy.js",
]

def _to_glob(patterns):
Expand Down
52 changes: 52 additions & 0 deletions tests/legacy-cli/e2e/tests/build/chunk-optimizer-lazy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import assert from 'node:assert/strict';
import { readdir } from 'node:fs/promises';
import { replaceInFile } from '../../utils/fs';
import { execWithEnv, ng } from '../../utils/process';

export default async function () {
// Add lazy routes.
await ng('generate', 'component', 'lazy-a');
await ng('generate', 'component', 'lazy-b');
await ng('generate', 'component', 'lazy-c');
await replaceInFile(
'src/app/app.routes.ts',
'routes: Routes = [];',
`routes: Routes = [
{
path: 'lazy-a',
loadComponent: () => import('./lazy-a/lazy-a').then(m => m.LazyA),
},
{
path: 'lazy-b',
loadComponent: () => import('./lazy-b/lazy-b').then(m => m.LazyB),
},
{
path: 'lazy-c',
loadComponent: () => import('./lazy-c/lazy-c').then(m => m.LazyC),
},
];`,
);

// Build without chunk optimization
await ng('build', '--output-hashing=none');
const unoptimizedFiles = await readdir('dist/test-project/browser');
const unoptimizedJsFiles = unoptimizedFiles.filter((f) => f.endsWith('.js'));

// Build with chunk optimization
await execWithEnv('ng', ['build', '--output-hashing=none'], {
...process.env,
NG_BUILD_OPTIMIZE_CHUNKS: '1',
});
const optimizedFiles = await readdir('dist/test-project/browser');
const optimizedJsFiles = optimizedFiles.filter((f) => f.endsWith('.js'));

// Check that the number of chunks is reduced but not all combined
assert.ok(
optimizedJsFiles.length < unoptimizedJsFiles.length,
`Expected chunk count to be less than ${unoptimizedJsFiles.length}, but was ${optimizedJsFiles.length}.`,
);
assert.ok(
optimizedJsFiles.length > 1,
`Expected more than one chunk, but found ${optimizedJsFiles.length}.`,
);
}