-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.js
75 lines (63 loc) · 1.7 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
67
68
69
70
71
72
73
74
75
import { build, context } from 'esbuild';
import svelte from 'esbuild-svelte';
import { sveltePreprocess } from 'svelte-preprocess';
import rm from './env/rm.js';
import meta from './env/meta.js';
import eslint from './env/eslint.js';
import nodemon from './env/nodemon.js';
import html from './env/html.js';
const DEV = process.argv.includes('--dev');
const APP = 'app/app.cjs';
const svelteOptions = {
compilerOptions: { dev: DEV },
preprocess: sveltePreprocess()
};
const options = {
bundle: true,
minify: !DEV,
// sourcemap: DEV && 'inline',
legalComments: 'none',
metafile: !DEV,
logLevel: 'info',
};
const clientOptions = {
...options,
entryPoints: ['src/client/app.ts'],
outdir: 'app/client/build',
inject: DEV ? ['./env/reload.js'] : [],
write: false,
plugins: [svelte(svelteOptions), html()],
loader: {
'.ico': 'dataurl',
'.png': 'dataurl'
},
conditions: ['svelte']
};
const serverOptions = {
...options,
platform: 'node',
entryPoints: ['src/server/app.ts'],
outfile: APP,
plugins: DEV ? [nodemon(APP)] : [],
define: {
'process.env.NODE_ENV': DEV ? '"dev"' : '"prod"'
},
};
await rm([APP]);
if (DEV) {
const client = await context(clientOptions);
const server = await context(serverOptions);
await client.watch();
await server.watch();
async function cleanup() {
await client.dispose();
await server.dispose();
}
process.on('SIGTERM', cleanup);
process.on("exit", cleanup);
} else {
const client = await build(clientOptions);
const server = await build(serverOptions);
await meta(client, 'client');
await meta(server, 'server');
}