-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrollupBuild.ts
60 lines (46 loc) · 1.88 KB
/
rollupBuild.ts
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { rollup } from "rollup";
import { getRollupConfig } from "./rollupConfig";
import type { packages } from "./type";
import type { OutputOptions, RollupOptions } from "rollup";
const build = async (packageName: string, rollupOptions: RollupOptions, mode: string, isUMD: boolean) => {
console.log(`[build] start build package ${packageName} with ${mode} mode ${isUMD ? "in umd format" : ""}`);
try {
const { output, ...options } = rollupOptions;
const bundle = await rollup(options);
await Promise.all((output as OutputOptions[]).map((output) => bundle.write(output)));
} catch (e) {
console.error(`[build] build package ${packageName} with ${mode} mode ${isUMD ? "in umd format error" : "error"} \n ${(e as Error).message}`);
throw e;
}
console.log(`[build] build package ${packageName} with ${mode} mode ${isUMD ? "in umd format success" : "success"}`);
};
const rollupBuild = async (packageName: packages) => {
const { allOtherDev, allOtherProd, allSingleOther, allSingleUMD, allUMDDev, allUMDProd } = await getRollupConfig(packageName);
const all: Array<() => Promise<void>> = [];
if (allOtherDev) {
all.push(() => build(packageName, allOtherDev, "development", false));
}
if (allOtherProd) {
all.push(() => build(packageName, allOtherProd, "production", false));
}
if (allSingleOther) {
all.push(() => build(packageName, allSingleOther, "process.nev", false));
}
if (allSingleUMD) {
all.push(() => build(packageName, allSingleUMD, "process.env", true));
}
if (allUMDDev) {
all.push(() => build(packageName, allUMDDev, "development", true));
}
if (allUMDProd) {
all.push(() => build(packageName, allUMDProd, "production", true));
}
await Promise.all(all.map((f) => f()));
};
const start = async () => {
await rollupBuild("env");
await rollupBuild("axios");
await rollupBuild("chakra");
process.exit(0);
};
start();