forked from Vidushi-GitHub/gcn.nasa.gov
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.js
55 lines (52 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
import esbuild from 'esbuild'
import { copyFile } from 'fs/promises'
import { glob } from 'glob'
import { extname } from 'node:path'
import { basename, dirname, join } from 'path'
const args = process.argv.slice(2)
const dev = args.includes('--dev')
const entryPoints = await glob(
'./app/{email-incoming,scheduled,table-streams}/*/index.ts'
)
/**
* @type {esbuild.BuildOptions}
*/
const options = {
bundle: true,
entryPoints,
logLevel: 'info',
outdir: 'build',
outbase: 'app',
outExtension: { '.js': '.cjs' },
external: ['@aws-sdk/*', 'aws-sdk'],
platform: 'node',
target: ['node20'],
minify: !dev,
sourcemap: dev,
metafile: true,
loader: { '.node': 'empty' },
plugins: [
{
name: 'copy Node API modules to output directories',
setup(build) {
build.onEnd(async ({ metafile: { outputs } }) => {
await Promise.all(
Object.entries(outputs).flatMap(([entryPoint, { inputs }]) =>
Object.keys(inputs)
.filter((input) => extname(input) === '.node')
.map((input) =>
copyFile(input, join(dirname(entryPoint), basename(input)))
)
)
)
})
},
},
],
}
if (dev) {
const ctx = await esbuild.context(options)
await ctx.watch()
} else {
await esbuild.build(options)
}