-
Notifications
You must be signed in to change notification settings - Fork 44
/
esbuild.js
67 lines (64 loc) · 1.65 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
import esbuild from 'esbuild'
import { copyFile, writeFile } 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: true,
sourcesContent: false,
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)))
)
)
)
})
},
},
{
name: 'write metafile to output directory',
setup(build) {
build.onEnd(async ({ metafile }) => {
await writeFile(
join(build.initialOptions.outdir, 'metafile.lambda.json'),
JSON.stringify(metafile)
)
})
},
},
],
}
if (dev) {
const ctx = await esbuild.context(options)
await ctx.watch()
} else {
await esbuild.build(options)
}