forked from pmndrs/postprocessing
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathesbuild.mjs
85 lines (78 loc) · 2.07 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
import { createRequire } from "module";
import { glsl } from "esbuild-plugin-glsl";
import esbuild from "esbuild";
const require = createRequire(import.meta.url);
const pkg = require("./package");
const date = (new Date()).toDateString();
const external = Object.keys(pkg.peerDependencies || {});
const minify = process.argv.includes("-m");
const watch = process.argv.includes("-w");
const plugins = [glsl({ minify })];
const banner = `/**
* ${pkg.name} v${pkg.version} build ${date}
* ${pkg.homepage}
* Copyright ${date.slice(-4)} ${pkg.author.name}
* @license ${pkg.license}
*/`;
await esbuild.build({
entryPoints: [
"src/images/lut/worker.js",
"src/images/smaa/worker.js"
],
outExtension: { ".js": ".txt" },
outdir: "tmp",
logLevel: "info",
format: "iife",
bundle: true,
minify,
watch
}).catch(() => process.exit(1));
await esbuild.build({
entryPoints: ["demo/src/index.js"],
outdir: "public/demo",
logLevel: "info",
format: "iife",
bundle: true,
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",
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",
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",
bundle: true,
globalName,
external,
plugins,
minify
}).catch(() => process.exit(1));