forked from pmndrs/postprocessing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.mjs
128 lines (116 loc) · 2.97 KB
/
esbuild.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
116
117
118
119
120
121
122
123
124
125
126
127
128
import { createRequire } from "module";
import { glsl } from "esbuild-plugin-glsl";
import tsPaths from "esbuild-ts-paths";
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 watch = process.argv.includes("-w");
const plugins = [glsl({ minify }), tsPaths()];
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}
*/`;
await esbuild.build({
entryPoints: await glob("src/**/worker.js"),
outExtension: { ".js": ".txt" },
outdir: "tmp",
target: "es6",
logLevel: "info",
format: "iife",
bundle: true,
minify,
watch
}).catch(() => process.exit(1));
await esbuild.build({
entryPoints: ["demo/src/index.js"],
outdir: "public/demo",
target: "es6",
logLevel: "info",
format: "iife",
bundle: true,
plugins,
minify,
watch
}).catch(() => process.exit(1));
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
}).catch(() => process.exit(1));
await esbuild.build({
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,
watch
}).catch(() => process.exit(1));
await esbuild.build({
entryPoints: ["src/index.js"],
outfile: `build/${pkg.name}.esm.js`,
banner: { js: banner },
logLevel: "info",
format: "esm",
target: "es2019",
bundle: true,
external,
plugins
}).catch(() => process.exit(1));
await esbuild.build({
entryPoints: ["src/index.js"],
outfile: `build/${pkg.name}.mjs`,
banner: { js: banner },
logLevel: "info",
format: "esm",
target: "es2019",
bundle: true,
external,
plugins
}).catch(() => process.exit(1));
// @todo Remove in next major release.
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: "es6",
bundle: true,
globalName,
external,
plugins
}).catch(() => process.exit(1));
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: "es6",
bundle: true,
globalName,
external,
plugins,
minify
}).catch(() => process.exit(1));