-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbun_build.js
43 lines (35 loc) · 1.05 KB
/
bun_build.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
import Bun from 'bun'
const args = process.argv.slice(2)
// console.log(args);
const wgslLoader = {
name: 'wgsl',
async setup(build) {
const { transpileWGSL } = await import('@use-gpu/shader/wgsl')
// when a .wgsl file is imported...
build.onLoad({ filter: /\.(wgsl)$/ }, async (args) => {
// read and parse the file
const source = await Bun.file(args.path).text()
const exports = transpileWGSL(source, args.path)
// console.log(exports);
// and returns it as a module
return {
contents: exports,
// exports,
loader: 'js', // special loader for JS objects
}
})
},
}
const result = await Bun.build({
entrypoints: [args[0]],
outdir: './output',
target: 'browser',
plugins: [wgslLoader],
})
if (!result.success) {
console.error('Build failed')
for (const message of result.logs) {
// Bun will pretty print the message object
console.error(message)
}
}