-
Notifications
You must be signed in to change notification settings - Fork 7
/
esbuild.ts
43 lines (39 loc) · 1.08 KB
/
esbuild.ts
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
import path from 'node:path'
import { cp } from 'node:fs/promises'
import { build } from 'esbuild'
import type { Plugin } from 'esbuild'
import esbuildPluginPino from 'esbuild-plugin-pino'
import glob from 'tiny-glob'
/** esbuild plugin to copy static folder to outdir */
function esbuildPluginFastifySwaggerUi(): Plugin {
return {
name: '@fastify/swagger-ui',
setup(build) {
const { outdir } = build.initialOptions
const fastifySwaggerUi = path.dirname(
require.resolve('@fastify/swagger-ui')
)
const source = path.join(fastifySwaggerUi, 'static')
const dest = path.join(outdir, 'static')
build.onEnd(async () => cp(source, dest, { recursive: true }))
}
}
}
;(async function () {
// Get all ts files
const entryPoints = await glob('src/**/*.ts')
build({
entryPoints,
logLevel: 'info',
outdir: 'build',
bundle: true,
minify: true,
platform: 'node',
format: 'cjs',
sourcemap: true,
plugins: [
esbuildPluginPino({ transports: ['pino-pretty'] }),
esbuildPluginFastifySwaggerUi()
]
})
})()