Skip to content

Commit 790f53f

Browse files
mydeaclaude
andcommitted
perf(browser): Parallelize CDN bundle builds
Add a lightweight parallel rollup runner that processes config arrays concurrently using the rollup JS API. Use it for @sentry/browser's build:bundle which runs 93 rollup builds (31 entrypoints × 3 variants). This reduces the browser bundle build from ~175s to ~65s (~2.6x faster), which was the critical path for the full `yarn build`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9b9d65c commit 790f53f

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Runs rollup builds in parallel for configs that export an array.
3+
* Usage: node rollupParallel.mjs <config-path>
4+
*/
5+
import { cpus } from 'os';
6+
import { pathToFileURL } from 'url';
7+
import { resolve } from 'path';
8+
import { rollup } from 'rollup';
9+
10+
const configPath = process.argv[2];
11+
if (!configPath) {
12+
console.error('Usage: node rollupParallel.mjs <config-path>');
13+
process.exit(1);
14+
}
15+
16+
const { default: configs } = await import(pathToFileURL(resolve(configPath)).href);
17+
const concurrency = cpus().length;
18+
const queue = [...configs];
19+
let done = 0;
20+
21+
async function worker() {
22+
while (queue.length > 0) {
23+
const config = queue.shift();
24+
const bundle = await rollup({ ...config, onwarn: () => {} });
25+
await bundle.write(config.output);
26+
await bundle.close();
27+
done++;
28+
process.stdout.write(`\r [${done}/${configs.length}] builds completed`);
29+
}
30+
}
31+
32+
console.log(`Running ${configs.length} rollup builds (concurrency: ${concurrency})...`);
33+
await Promise.all(Array.from({ length: concurrency }, worker));
34+
console.log('\nDone.');

packages/browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"scripts": {
5858
"build": "run-p build:transpile build:bundle build:types",
5959
"build:dev": "run-p build:transpile build:types",
60-
"build:bundle": "rollup -c rollup.bundle.config.mjs",
60+
"build:bundle": "node ../../dev-packages/rollup-utils/rollupParallel.mjs rollup.bundle.config.mjs",
6161
"build:transpile": "rollup -c rollup.npm.config.mjs",
6262
"build:types": "run-s build:types:core build:types:downlevel",
6363
"build:types:core": "tsc -p tsconfig.types.json",

0 commit comments

Comments
 (0)