-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
56 lines (47 loc) · 1.75 KB
/
build.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
import * as esbuild from 'esbuild';
const plural = n => n === 1 ? '' : 's';
let examplePlugin = {
name: 'example',
setup(build) {
build.onEnd(result => {
console.log(`build ended with ${result.errors.length} error${plural(result.errors.length)}`);
});
},
};
const ctx = await esbuild.context({
entryPoints: ['./src/index.js'],
bundle: true,
format: 'esm',
define: {
// This should be defined to true or false, depending on whether we want to turn
// on debug checks. These will slow down the code but help to catch implementation
// bugs and invariant violations.
// DEBUG: 'false',
// globalThis: "false",
// In order for code that uses the global debug flag to work correctly, we define
// the attribute on `globalThis` so that `DEBUG && ...` statements resolve properly
// during testing. In production, the debug variable will be replaced, so we need not
// reference globalThis.
// Hence, we define this replacement in order that our module not mutate global state.
// This is all a bit ugly, but it works until I figure out a better way.
},
plugins: [examplePlugin],
outfile: 'dist/made-of-bits.js',
minify: true,
// sourcemap: 'inline'
// minify: false,
// sourcemap: 'inline'
});
await ctx.watch();
console.log('watching...');
const { host, port } = await ctx.serve({
servedir: 'dist',
port: 4242,
// SSL certificates for local serving generated using the following command,
// which was taken from the esbuild documentation: https://esbuild.github.io/api/#https
//
// openssl req -x509 -newkey rsa:4096 -keyout silk.key -out silk.cert -days 9999 -nodes -subj /CN=127.0.0.1
keyfile: 'silk.key',
certfile: 'silk.cert',
});
console.log(`serving on https://${host}:${port}`);