-
-
Notifications
You must be signed in to change notification settings - Fork 216
/
esbuild.js
141 lines (123 loc) · 2.99 KB
/
esbuild.js
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { createRequire } from "module";
import { glsl } from "esbuild-plugin-glsl";
import glob from "tiny-glob";
import esbuild from "esbuild";
const require = createRequire(import.meta.url);
const pkg = require("./package");
const minify = process.argv.includes("-m");
const plugins = [glsl({ minify })];
const external = ["three", "spatial-controls", "tweakpane"];
const date = new Date();
const banner = `/**
* ${pkg.name} v${pkg.version} build ${date.toDateString()}
* ${pkg.homepage}
* Copyright 2015-${date.getFullYear()} ${pkg.author.name}
* @license ${pkg.license}
*/`;
const workers = {
entryPoints: await glob("./src/**/worker.js"),
outExtension: { ".js": ".txt" },
outdir: "./tmp",
target: "es2019",
logLevel: "info",
format: "iife",
bundle: true,
minify
};
const demo = {
entryPoints: ["./demo/src/index.js"],
outdir: "./public/demo",
target: "es6",
logLevel: "info",
format: "iife",
bundle: true,
plugins,
minify
};
const manual = {
entryPoints: ["./manual/assets/js/src/index.js"]
.concat(await glob("./manual/assets/js/src/demos/*.js")),
outdir: "./manual/assets/js/dist",
logLevel: "info",
format: "iife",
target: "es6",
bundle: true,
external,
plugins,
minify
};
await esbuild.build({
entryPoints: ["./manual/assets/js/libs/vendor.js"],
outdir: "./manual/assets/js/dist/libs",
globalName: "VENDOR",
target: "es6",
logLevel: "info",
format: "iife",
bundle: true,
minify
});
if(process.argv.includes("-w")) {
const ctxWorkers = await esbuild.context(workers);
const ctxDemo = await esbuild.context(demo);
const ctxManual = await esbuild.context(manual);
await ctxWorkers.watch();
await ctxDemo.watch();
await ctxManual.watch();
} else {
await esbuild.build(workers);
await esbuild.build(demo);
await esbuild.build(manual);
}
await esbuild.build({
entryPoints: ["./src/index.js"],
outfile: "./build/index.js",
banner: { js: banner },
logLevel: "info",
format: "esm",
target: "es2019",
bundle: true,
external,
plugins
});
// @todo Remove in next major release.
await esbuild.build({
entryPoints: ["./src/index.js"],
outfile: "./build/index.cjs",
banner: { js: banner },
logLevel: "info",
format: "cjs",
target: "es2019",
bundle: true,
external,
plugins
});
const globalName = pkg.name.replace(/-/g, "").toUpperCase();
const requireShim = "if(typeof window===\"object\"&&!window.require)window.require=()=>window.THREE;";
const footer = `if(typeof module==="object"&&module.exports)module.exports=${globalName};`;
await esbuild.build({
entryPoints: ["./src/index.js"],
outfile: `./build/${pkg.name}.js`,
banner: { js: `${banner}\n${requireShim}` },
footer: { js: footer },
logLevel: "info",
format: "iife",
target: "es2019",
bundle: true,
globalName,
external,
plugins
});
await esbuild.build({
entryPoints: ["./src/index.js"],
outfile: `./build/${pkg.name}.min.js`,
banner: { js: `${banner}\n${requireShim}` },
footer: { js: footer },
logLevel: "info",
format: "iife",
target: "es2019",
bundle: true,
globalName,
external,
plugins,
minify
});