-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.js
58 lines (53 loc) · 1.43 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import * as esbuild from 'esbuild';
import { copyFile, mkdir } from 'fs/promises';
import { existsSync } from 'fs';
import path from 'path';
const WATCH = process.argv.includes('--watch');
// Ensure dist directory exists
if (!existsSync('./dist')) {
await mkdir('./dist');
}
// Copy static files
await copyFile('./src/login.html', './dist/login.html');
await copyFile('./src/sign.html', './dist/sign.html');
// Build configuration
const buildOptions = {
entryPoints: ['./src/main.js'],
bundle: true,
format: 'esm',
outfile: './dist/main.js',
minify: !WATCH,
sourcemap: WATCH,
loader: {
'.png': 'dataurl',
'.svg': 'dataurl'
},
target: ['es2020'],
platform: 'browser',
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
'global': 'window',
},
inject: [path.join(new URL('.', import.meta.url).pathname, 'src/polyfills.js')],
alias: {
// Add browser-compatible alternatives for Node.js built-in modules
crypto: 'crypto-browserify',
stream: 'stream-browserify',
buffer: 'buffer',
util: 'util',
path: 'path-browserify',
http: 'stream-http',
https: 'https-browserify',
events: 'events',
url: 'url',
fs: 'browserify-fs'
},
};
if (WATCH) {
const context = await esbuild.context(buildOptions);
await context.watch();
console.log('Watching for changes...');
} else {
await esbuild.build(buildOptions);
console.log('Build complete');
}