-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathrollupParallel.mjs
More file actions
36 lines (31 loc) · 1.09 KB
/
rollupParallel.mjs
File metadata and controls
36 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* eslint-disable no-console */
/**
* Runs rollup builds in parallel for configs that export an array.
* Usage: node rollupParallel.mjs <config-path>
*/
import { availableParallelism } from 'os';
import { pathToFileURL } from 'url';
import { resolve } from 'path';
import { rollup } from 'rollup';
const configPath = process.argv[2];
if (!configPath) {
console.error('Usage: node rollupParallel.mjs <config-path>');
process.exit(1);
}
const { default: configs } = await import(pathToFileURL(resolve(configPath)).href);
const concurrency = availableParallelism();
const queue = [...configs];
let done = 0;
async function worker() {
while (queue.length > 0) {
const config = queue.shift();
const bundle = await rollup({ ...config, onwarn: console.warn });
await bundle.write(config.output);
await bundle.close();
done++;
process.stdout.write(`\r [${done}/${configs.length}] builds completed`);
}
}
console.log(`Running ${configs.length} rollup builds (concurrency: ${concurrency})...`);
await Promise.all(Array.from({ length: concurrency }, worker));
console.log('\nDone.');