Skip to content

Commit 6dd5625

Browse files
committed
perf(@angular/build): default chunk optimization to use Rolldown
Now that Rolldown is stable, swap the default chunk optimizer from Rollup to Rolldown to utilize native compilation benefits and optimize heap memory usage. Rollup remains an optional peer dependency of @angular/build, allowing users to opt back into Rollup by setting the environment variable `NG_BUILD_CHUNKS_ROLLDOWN=false` if it is also installed in the project.
1 parent 2fd0530 commit 6dd5625

5 files changed

Lines changed: 58 additions & 35 deletions

File tree

packages/angular/build/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"parse5-html-rewriting-stream": "8.0.1",
3737
"picomatch": "4.0.4",
3838
"piscina": "5.2.0",
39-
"rollup": "4.62.0",
39+
"rolldown": "1.1.1",
4040
"sass": "1.101.0",
4141
"semver": "7.8.4",
4242
"source-map-support": "0.5.21",
@@ -55,7 +55,7 @@
5555
"less": "4.6.6",
5656
"ng-packagr": "22.1.0-next.2",
5757
"postcss": "8.5.15",
58-
"rolldown": "1.1.1",
58+
"rollup": "4.62.0",
5959
"rxjs": "7.8.2",
6060
"vitest": "4.1.9"
6161
},
@@ -73,6 +73,7 @@
7373
"less": "^4.2.0",
7474
"ng-packagr": "0.0.0-NG-PACKAGR-PEER-DEP",
7575
"postcss": "^8.4.0",
76+
"rollup": "^4.0.0",
7677
"tailwindcss": "^2.0.0 || ^3.0.0 || ^4.0.0",
7778
"tslib": "^2.3.0",
7879
"typescript": ">=6.0 <6.1",
@@ -112,6 +113,9 @@
112113
"postcss": {
113114
"optional": true
114115
},
116+
"rollup": {
117+
"optional": true
118+
},
115119
"tailwindcss": {
116120
"optional": true
117121
},

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import type { Message, Metafile } from 'esbuild';
2121
import assert from 'node:assert';
22-
import { type Plugin, rollup } from 'rollup';
22+
import type { Plugin } from 'rollup';
2323
import { BundleContextResult } from '../../tools/esbuild/bundler-context';
2424
import {
2525
type BuildOutputFile,
@@ -306,6 +306,15 @@ export async function optimizeChunks(
306306
});
307307
optimizedOutput = result.output;
308308
} else {
309+
let rollup;
310+
try {
311+
rollup = (await import('rollup')).rollup;
312+
} catch {
313+
throw new Error(
314+
`Rollup is required when 'NG_BUILD_CHUNKS_ROLLDOWN' is set to false. ` +
315+
`Please install 'rollup' manually (e.g. 'npm install rollup --save-dev') to use this fallback.`,
316+
);
317+
}
309318
bundle = await rollup({
310319
input: mainFile,
311320
plugins: plugins as Plugin[],

packages/angular/build/src/utils/environment-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export const allowMinify = debugOptimize.minify;
106106
* Allows using Rolldown for chunk optimization instead of Rollup.
107107
* This is useful for debugging and testing scenarios.
108108
*/
109-
export const useRolldownChunks = parseTristate(process.env['NG_BUILD_CHUNKS_ROLLDOWN']) ?? false;
109+
export const useRolldownChunks = parseTristate(process.env['NG_BUILD_CHUNKS_ROLLDOWN']) ?? true;
110110

111111
/**
112112
* Some environments, like CircleCI which use Docker report a number of CPUs by the host and not the count of available.

pnpm-lock.yaml

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/e2e/tests/build/chunk-optimizer-env.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,30 @@ export default async function () {
8686
`Expected build with threshold 4 and 3 chunks to NOT be optimized. Thresh 4: ${jsFiles3Thresh4.length}, Unoptimized: ${jsFiles3Unopt.length}`,
8787
);
8888

89-
// Case 4: Opt into Rolldown
90-
await installPackage('rolldown@1.0.0-rc.12');
89+
// Case 4: Opt back into Rollup (requires manual install since it's an optional peer dependency)
90+
await installPackage('rollup@4.62.0');
9191
try {
9292
await execWithEnv('ng', ['build', '--output-hashing=none'], {
9393
...process.env,
94-
NG_BUILD_CHUNKS_ROLLDOWN: '1',
94+
NG_BUILD_CHUNKS_ROLLDOWN: 'false',
9595
NG_BUILD_OPTIMIZE_CHUNKS: 'true',
9696
});
97-
const filesRolldown = await readdir('dist/test-project/browser');
98-
const jsFilesRolldown = filesRolldown.filter((f) => f.endsWith('.js'));
97+
const filesRollup = await readdir('dist/test-project/browser');
98+
const jsFilesRollup = filesRollup.filter((f) => f.endsWith('.js'));
9999

100-
assert.ok(jsFilesRolldown.length > 0, 'Expected Rolldown build to produce output files.');
100+
assert.ok(jsFilesRollup.length > 0, 'Expected Rollup build to produce output files.');
101101
} finally {
102102
// Clean up
103-
await uninstallPackage('rolldown');
103+
await uninstallPackage('rollup');
104104
}
105+
106+
// Case 5: Opt back into Rollup without installing it (should throw a helpful error)
107+
await assert.rejects(
108+
execWithEnv('ng', ['build', '--output-hashing=none'], {
109+
...process.env,
110+
NG_BUILD_CHUNKS_ROLLDOWN: 'false',
111+
NG_BUILD_OPTIMIZE_CHUNKS: 'true',
112+
}),
113+
/Rollup is required when 'NG_BUILD_CHUNKS_ROLLDOWN' is set to false/,
114+
);
105115
}

0 commit comments

Comments
 (0)