Repository navigation
Expand file tree
/
Copy pathesbuild.config.js
More file actions
90 lines (87 loc) · 2.33 KB
/
Copy pathesbuild.config.js
File metadata and controls
90 lines (87 loc) · 2.33 KB
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
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import esbuild from "esbuild";
import fs from "node:fs";
const releaseBanner = `/*!
* WasmGPU v0.10.0
* Released on Monday, August 31, 2026
* WebGPU × WebAssembly rendering and computing engine for scientific workloads in the browser
* Copyright (c) Zushah and contributors
* SPDX-License-Identifier: MPL-2.0
* Source: https://github.com/Zushah/WasmGPU
* Website: https://zushah.github.io/WasmGPU
*/
`;
const wgslMinify = {
name: "wgsl-minify",
setup(build) {
build.onLoad({ filter: /\.wgsl$/ }, async (args) => {
let text = await fs.promises.readFile(args.path, "utf8");
text = text
.replace(/\/\*[\s\S]*?\*\//g, "")
.replace(/\/\/.*$/gm, "")
.replace(/\s+/g, " ")
.trim();
return { contents: text, loader: "text" };
});
}
};
const common = {
bundle: true,
platform: "browser",
target: ["es2023"],
external: ["node:*"],
loader: { ".wasm": "file" },
plugins: [wgslMinify],
assetNames: "[name]",
logLevel: "info",
banner: { js: releaseBanner }
};
try {
await esbuild.build({
...common,
entryPoints: ["./typescript/index.ts"],
define: {
__WASMGPU_BASE_URL__: "import.meta.url"
},
format: "esm",
minify: false,
outfile: "./release/WasmGPU.js"
});
await esbuild.build({
...common,
entryPoints: ["./typescript/index.ts"],
define: {
__WASMGPU_BASE_URL__: "import.meta.url"
},
format: "esm",
minify: true,
outfile: "./release/WasmGPU.min.js"
});
await esbuild.build({
...common,
entryPoints: ["./typescript/index.iife.ts"],
define: {
__WASMGPU_BASE_URL__: "\"__CURRENT_SCRIPT__\""
},
format: "iife",
globalName: "WasmGPU",
minify: true,
outfile: "./release/WasmGPU.iife.min.js",
footer: {
js: `
(() => {
const g = globalThis;
if (g.WasmGPU && g.WasmGPU.default) g.WasmGPU = g.WasmGPU.default;
})();`
}
});
fs.copyFileSync("./wasm/wasm.wasm", "./release/wasm.wasm");
const wasmJavaScript = fs.readFileSync("./wasm/wasm.js", "utf8");
fs.writeFileSync("./release/wasm.js", `${releaseBanner}\n${wasmJavaScript}`);
} catch (e) {
process.exit(1);
}