-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathesbuild.config.js
More file actions
79 lines (71 loc) · 1.88 KB
/
esbuild.config.js
File metadata and controls
79 lines (71 loc) · 1.88 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
import esbuild from 'esbuild';
import copy from 'esbuild-copy-files-plugin';
import path from 'path';
const nodeBuiltIns = {
name: 'node-builtins',
setup(build) {
const filter = /^(fs|path|crypto)$/;
build.onResolve({ filter }, args => ({
path: args.path,
namespace: 'node-builtins-ns',
}));
build.onLoad({ filter, namespace: 'node-builtins-ns' }, () => ({
contents: 'export default {}',
loader: 'js',
}));
},
};
const libraryName = 'redcube.webgpu';
const isWatch = process.argv.includes('--watch');
const isServe = process.argv.includes('--serve');
const __dirname = import.meta.dirname;
const esbuildOptions = {
entryPoints: [path.join(__dirname, `/src/${libraryName}.ts`)],
bundle: true,
outfile: path.join(__dirname, `/dist/${libraryName}.js`),
format: 'iife',
globalName: 'redcube',
sourcemap: true,
chunkNames: 'libs/[name]',
assetNames: 'assets/[name]',
loader: {
'.glsl': 'text',
'.vert': 'text',
'.frag': 'text',
'.h': 'text',
'.hdr': 'file',
'.jpeg': 'dataurl',
'.jpg': 'dataurl',
'.png': 'dataurl',
'.gif': 'dataurl',
},
plugins: [
nodeBuiltIns,
copy({
source: ['./index.html', './libktx.wasm', './draco_decoder.wasm', './glslang.wasm', './twgsl.wasm', './src/images'],
target: './dist',
}),
],
};
async function build() {
if (isServe) {
const ctx = await esbuild.context(esbuildOptions);
await ctx.watch();
const { host, port } = await ctx.serve({
servedir: 'dist',
port: 8080,
});
console.log(`Serving at http://${host}:${port}`);
} else if (isWatch) {
const ctx = await esbuild.context(esbuildOptions);
await ctx.watch();
console.log('Watching for changes...');
} else {
await esbuild.build(esbuildOptions);
console.log('Build finished.');
}
}
build().catch((e) => {
console.error(e);
process.exit(1);
});