-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
57 lines (51 loc) · 1.22 KB
/
build.js
File metadata and controls
57 lines (51 loc) · 1.22 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
const esbuild = require('esbuild');
const path = require('path');
const buildOptions = {
entryPoints: ['src/ui/main.ts'],
bundle: true,
outfile: 'src/ui/dist/bundle.js',
format: 'iife',
target: 'es2020',
minify: process.env.NODE_ENV === 'production',
sourcemap: process.env.NODE_ENV !== 'production',
globalName: 'ChatApp',
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
},
loader: {
'.ts': 'ts',
},
tsconfig: 'tsconfig.json'
};
// Build function
async function build() {
try {
await esbuild.build(buildOptions);
console.log('✅ Build completed successfully');
} catch (error) {
console.error('❌ Build failed:', error);
process.exit(1);
}
}
// Watch function
async function watch() {
try {
const ctx = await esbuild.context(buildOptions);
await ctx.watch();
console.log('👀 Watching for changes...');
} catch (error) {
console.error('❌ Watch failed:', error);
process.exit(1);
}
}
// Export for programmatic use
module.exports = { build, watch, buildOptions };
// CLI usage
if (require.main === module) {
const command = process.argv[2];
if (command === 'watch') {
watch();
} else {
build();
}
}