-
Notifications
You must be signed in to change notification settings - Fork 1
/
esbuild.js
66 lines (58 loc) · 1.42 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
59
60
61
62
63
64
65
66
import { build, context } from 'esbuild';
import svelte from 'esbuild-svelte';
import { sveltePreprocess } from 'svelte-preprocess';
import rm from './env/rm.js';
import log from './env/log.js';
import meta from './env/meta.js';
const DEV = process.argv.includes('--dev');
const serveOptions = {
servedir: 'public',
onRequest(args) {
console.log(
// `%d %s %dms %s`,
args.status,
args.method,
args.timeInMS,
args.remoteAddress + args.path,
);
},
};
const svelteOptions = {
compilerOptions: {
dev: DEV,
css: 'external',
immutable: true,
runes: true,
modernAst: true
},
preprocess: [
sveltePreprocess({
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',
metafile: !DEV
};
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 meta(await build(buildOptions));
};