-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbun.config.js
More file actions
37 lines (32 loc) · 874 Bytes
/
bun.config.js
File metadata and controls
37 lines (32 loc) · 874 Bytes
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
import path from 'path'
import fs from 'fs'
const config = {
sourcemap: 'external',
entrypoints: ['app/javascript/application.ts'],
outdir: path.join(process.cwd(), 'app/assets/builds'),
}
const build = async (config) => {
const result = await Bun.build(config)
if (!result.success) {
if (process.argv.includes('--watch')) {
console.error('Build failed')
for (const message of result.logs) {
console.error(message)
}
return
} else {
throw new AggregateError(result.logs, 'Build failed')
}
}
};
(async () => {
await build(config)
if (process.argv.includes('--watch')) {
fs.watch(path.join(process.cwd(), 'app/javascript'), { recursive: true }, (eventType, filename) => {
console.log(`File changed: ${filename}. Rebuilding...`)
build(config)
})
} else {
process.exit(0)
}
})()