blob: d18c450ca55c41b0dad8b1c79fda6f4b211a655f (
plain)
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
37
38
39
40
41
42
|
import { rollup } from "rollup";
import { loadConfigFile } from "rollup/loadConfigFile";
import path from "node:path";
import { fileURLToPath } from "node:url";
const dirname = path.dirname( fileURLToPath( import.meta.url ) );
const pureEsmConfigPath = path.resolve(
dirname, "..", "rollup-pure-esm.config.js" );
const commonJSConfigPath = path.resolve(
dirname, "..", "rollup-commonjs.config.js" );
// See https://rollupjs.org/javascript-api/#programmatically-loading-a-config-file
async function runRollup( name, configPath ) {
console.log( `Running Rollup, version: ${ name }` );
// options is an array of "inputOptions" objects with an additional
// "output" property that contains an array of "outputOptions".
// We generate a single output so the array only has one element.
const {
options: [ optionsObj ],
warnings
} = await loadConfigFile( configPath, {} );
// "warnings" wraps the default `onwarn` handler passed by the CLI.
// This prints all warnings up to this point:
warnings.flush();
const bundle = await rollup( optionsObj );
await Promise.all( optionsObj.output.map( bundle.write ) );
console.log( `Build completed: Rollup, version: ${ name }` );
}
export async function runRollupPureEsm() {
await runRollup( "pure ESM", pureEsmConfigPath );
}
export async function runRollupEsmAndCommonJs() {
await runRollup( "ESM + CommonJS", commonJSConfigPath );
}
|