-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbun.config.js
38 lines (33 loc) · 898 Bytes
/
bun.config.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
import path from 'path'
import fs from 'fs'
import Bun from 'bun'
const config = {
sourcemap: 'external',
entrypoints: ['app/javascript/application.js'],
outdir: path.join(process.cwd(), 'app/assets/builds'),
minify: true
}
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)
}
} 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)
}
})()