forked from davidenke/context-filter-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.ts
43 lines (40 loc) · 1.08 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
import { parseArgs } from 'node:util';
import { type BuildOptions, build, context } from 'esbuild';
import { dtsPlugin } from 'esbuild-plugin-d.ts';
const { values } = parseArgs({
options: {
port: { type: 'string', default: '3500' },
serve: { type: 'boolean' },
},
});
const { port, serve } = values;
const options: BuildOptions = {
entryPoints: ['src/index.ts', 'src/index.html', 'src/mocks/mock-1.jpg', 'src/mocks/mock-2.png'],
outdir: 'dist',
format: 'esm',
bundle: true,
sourcemap: true,
minify: true,
splitting: false,
target: ['es6'],
loader: { '.html': 'copy', '.jpg': 'copy', '.png': 'copy' },
plugins: [dtsPlugin()],
};
try {
if (serve) {
const ctx = await context({
...options,
banner: {
js: `new EventSource('/esbuild').addEventListener('change', () => location.reload())`,
},
});
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);
}