-
Notifications
You must be signed in to change notification settings - Fork 52
/
rollup.config.mjs
115 lines (111 loc) · 3.73 KB
/
rollup.config.mjs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import nodeResolve from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import typescript from "@rollup/plugin-typescript";
import fs from "fs";
import cleanup from "rollup-plugin-cleanup";
import replaceRegEx from "rollup-plugin-re";
function bundle(input, output, isMain, external = []) {
const isWpilib = process.env.ASCOPE_DISTRIBUTOR === "WPILIB";
return {
input: "src/" + input,
output: {
file: "bundles/" + output,
format: isMain ? "cjs" : "es"
},
context: "this",
external: external,
plugins: [
typescript(),
nodeResolve({
preferBuiltins: true
}),
commonjs(),
cleanup(),
json(),
replace({
preventAssignment: true,
values: {
__distributor__: isWpilib ? "WPILib" : "FRC6328",
__build_date__: new Date().toLocaleString("en-US", {
timeZone: "UTC",
hour12: false,
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric",
timeZoneName: "short"
}),
__copyright__: JSON.parse(
fs.readFileSync("package.json", {
encoding: "utf-8"
})
).build.copyright
}
}),
replaceRegEx({
patterns: [
// Remove unused eval in protobufjs
// https://github.com/protobufjs/protobuf.js/issues/593
{
test: /eval.*\(moduleName\);/g,
replace: "undefined;"
}
]
})
],
onwarn(message, warn) {
// Hide warnings about protobufjs circular dependencies
// https://github.com/protobufjs/protobuf.js/issues/1402
if (message.code === "CIRCULAR_DEPENDENCY") return;
warn(message);
}
};
}
const mainBundles = [
bundle("main/main.ts", "main.js", true, [
"electron",
"electron-fetch",
"fs",
"jsonfile",
"net",
"os",
"path",
"ssh2",
"download",
"ytdl-core",
"tesseract.js"
]),
bundle("preload.ts", "preload.js", true, ["electron"])
];
const largeRendererBundles = [bundle("hub/hub.ts", "hub.js", false), bundle("satellite.ts", "satellite.js", false)];
const smallRendererBundles = [
bundle("editRange.ts", "editRange.js", false),
bundle("unitConversion.ts", "unitConversion.js", false),
bundle("renameTab.ts", "renameTab.js", false),
bundle("editFov.ts", "editFov.js", false),
bundle("sourceListHelp.ts", "sourceListHelp.js", false),
bundle("betaWelcome.ts", "betaWelcome.js", false),
bundle("export.ts", "export.js", false),
bundle("download.ts", "download.js", false),
bundle("preferences.ts", "preferences.js", false),
bundle("licenses.ts", "licenses.js", false)
];
const workerBundles = [
bundle("hub/dataSources/rlog/rlogWorker.ts", "hub$rlogWorker.js", false),
bundle("hub/dataSources/wpilog/wpilogWorker.ts", "hub$wpilogWorker.js", false),
bundle("hub/dataSources/dslog/dsLogWorker.ts", "hub$dsLogWorker.js", false),
bundle("hub/exportWorker.ts", "hub$exportWorker.js", false),
bundle("shared/renderers/threeDimension/workers/loadField.ts", "shared$loadField.js", false),
bundle("shared/renderers/threeDimension/workers/loadRobot.ts", "shared$loadRobot.js", false)
];
export default (cliArgs) => {
if (cliArgs.configMain === true) return mainBundles;
if (cliArgs.configLargeRenderers === true) return largeRendererBundles;
if (cliArgs.configSmallRenderers === true) return smallRendererBundles;
if (cliArgs.configWorkers === true) return workerBundles;
return [...mainBundles, ...largeRendererBundles, ...smallRendererBundles, ...workerBundles];
};