-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
58 lines (48 loc) · 1.54 KB
/
index.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
import { rollup } from "rollup";
import type { OutputOptions } from "rollup";
import { terser } from "rollup-plugin-terser";
import { replace } from "./rollup-plugins/rollup-plugin-replace-file.js";
import { prep, transformPlugin, injectWorkers } from "./rollup-plugins/rollup-plugin-prep-source.js";
import { writeFileSync, readFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from 'url';
import { minify } from "terser";
const workerOptions: OutputOptions = {
banner: "self.module = self.module || {};",
format: "cjs",
exports: "auto"
};
const mainOptions: OutputOptions = {
format: "esm"
};
const bootstrapper = readFileSync(
join(
dirname(fileURLToPath(import.meta.url)),
"./templates/cesiumWorkerBootstrapper.js"),
"utf8");
const bundleWorkers = await rollup({
input: "./cesium/Source/Workers/cesiumWorkers.js",
plugins: [
prep(),
replace("./cesium/Source", "./src/source-files/Source", false),
transformPlugin()
]
});
let workerSrc = `
${(await bundleWorkers.generate(workerOptions)).output[0].code}
${bootstrapper}
`;
const bundleMain = await rollup({
input: "./cesium/Source/Cesium.js",
plugins: [
terser(),
prep(),
replace("./cesium/Source", "./.Source/Source", false),
transformPlugin(),
injectWorkers((await minify(workerSrc, {
})).code?.toString() as string)
]
});
let mainSrc =
(await bundleMain.generate(mainOptions)).output[0].code;
writeFileSync(`./dist/c137.mjs`, mainSrc);