-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.js
58 lines (50 loc) · 1.33 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 { 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';
import proxy from './env/proxy.js';
const DEV = process.argv.includes('--dev');
const SPA = process.argv.includes('--spa');
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,
mainFields: ['svelte', 'module', 'main'],
};
await rm(['public/build']);
if (DEV) {
const ctx = await context(buildOptions);
await ctx.watch();
await ctx.serve({ servedir: 'public' });
SPA && proxy().listen(8080);
process.on('SIGTERM', ctx.dispose);
process.on('exit', ctx.dispose);
} else {
await meta(await build(buildOptions));
}