-
Notifications
You must be signed in to change notification settings - Fork 9
/
esbuild.config.cjs
43 lines (37 loc) · 1.23 KB
/
esbuild.config.cjs
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
const fs = require('node:fs')
const esbuild = require('esbuild')
const catcher = (error) => {
console.error(error)
// eslint-disable-next-line unicorn/no-process-exit
process.exit(1)
}
const targets = { Browser: 'browser', Node: 'node' }
const builder = (entryPoints, outdir = 'dist', platform = targets.Node) =>
esbuild
.build({
bundle: true,
entryPoints,
format: 'esm',
metafile: true,
minify: true,
outdir,
platform,
sourcemap: true,
sourcesContent: false,
...(platform === targets.Node
? { packages: 'external', target: 'node14' }
: {
jsx: 'automatic',
target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge18', 'ios11']
})
})
.then((result) => esbuild.analyzeMetafile(result.metafile))
.then(console.info)
fs.mkdirSync('dist/homebridge-ui/public', { recursive: true })
fs.copyFileSync('src/ui/public/index.html', 'dist/homebridge-ui/public/index.html')
const deliverables = [
[['src/index.ts', 'src/pair.ts']],
[['src/ui/server.ts'], 'dist/homebridge-ui/'],
[['src/ui/index.tsx'], 'dist/homebridge-ui/public/', targets.Browser]
]
for (const payload of deliverables) builder(...payload).catch(catcher)