-
Notifications
You must be signed in to change notification settings - Fork 22
/
esbuild.config.ts
49 lines (44 loc) · 1.1 KB
/
esbuild.config.ts
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
import { parseArgs } from 'node:util';
import { build, type BuildOptions, context } from 'esbuild';
import copyStaticFiles from 'esbuild-copy-static-files';
const { values } = parseArgs({
options: {
port: { type: 'string', default: '3500' },
serve: { type: 'boolean' },
},
});
const { port, serve } = values;
const options: BuildOptions = {
entryPoints: [
'src/index.ts',
'src/polyfill.ts',
'src/example.ts',
'src/example.css',
'src/example.jpg',
],
outdir: 'dist',
format: 'esm',
bundle: true,
sourcemap: true,
minify: true,
splitting: false,
target: ['es6'],
loader: { '.jpg': 'copy' },
plugins: [
copyStaticFiles({ src: 'src/module.d.ts', dest: 'dist/index.d.ts' }),
copyStaticFiles({ src: 'src/example.html', dest: 'dist/index.html' }),
],
};
try {
if (serve) {
const ctx = await context(options);
await ctx.watch();
await ctx.serve({ servedir: 'dist', port: Number(port) });
console.log(`> Serving on http://localhost:${port}`);
} else {
await build(options);
}
} catch (error) {
console.error(error);
process.exit(1);
}