-
Notifications
You must be signed in to change notification settings - Fork 1
/
esbuild.js
49 lines (41 loc) · 1.05 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
import { build, context } from 'esbuild';
import svelte from 'esbuild-svelte';
import preprocess from 'svelte-preprocess';
import rm from './env/rm.js';
import log from './env/log.js';
const DEV = process.argv.includes('--dev');
const serveOptions = {
servedir: 'public'
};
const svelteOptions = {
compilerOptions: { dev: DEV, runes: true, modernAst: true },
preprocess: [
preprocess({
sourceMap: DEV,
typescript: true,
}),
]
};
const buildOptions = {
bundle: true,
minify: !DEV,
sourcemap: DEV,
entryPoints: ['src/app.ts'],
outdir: 'public/build',
format: 'esm',
loader: { '.svg': 'text' },
plugins: [svelte(svelteOptions), log],
inject: DEV ? ['./env/lr.js'] : [],
legalComments: "none",
logLevel: 'info'
};
await rm('public/build');
if (DEV) {
const ctx = await context(buildOptions);
await ctx.watch();
await ctx.serve(serveOptions);
process.on('SIGTERM', ctx.dispose);
process.on("exit", ctx.dispose);
} else {
await build(buildOptions);
}