-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.js
43 lines (40 loc) · 1.04 KB
/
esbuild.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 { build, context, } from 'esbuild'
/**
* @type {import('esbuild').BuildOptions}
*/
const config = {
entryPoints: ['./src/index.ts'],
outfile: './dist/index.js',
sourcemap: 'both',
minify: false,
bundle: true,
platform: 'browser',
target: ['es2020'],
loader: { '.ts': 'ts' },
define: {
'process.env.NODE_DEBUG': 'false',
global: 'globalThis'
},
}
// Check command line arguments
const isWatch = process.argv.includes('--watch')
const isServe = process.argv.includes('--serve')
if (isWatch || isServe) {
// Create a context for either watch or serve mode
context(config).then(async (ctx) => {
// Start serve mode if requested
if (isServe) {
const { host, port } = await ctx.serve({ servedir: './dist', })
console.log(`Server running at http://${host.replace('0.0.0.0', '127.0.0.1')}:${port}`)
} else {
await ctx.watch()
console.log('Watching for changes...')
}
})
} else {
// Regular one-time build
build(config).catch((err) => {
console.error(err)
process.exit(1)
})
}