-
-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathesbuild.ts
More file actions
52 lines (46 loc) · 1.18 KB
/
Copy pathesbuild.ts
File metadata and controls
52 lines (46 loc) · 1.18 KB
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
/* eslint-disable no-console */
import { context } from 'esbuild'
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
//@ts-ignore
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const watch = process.argv.includes('--watch')
const getPath = (file: string) => resolve(__dirname, file)
const formats = ['esm', 'cjs'] as const
const contexts = await Promise.all(
formats.map((format) =>
context({
entryPoints: [getPath('src/index.mts')],
bundle: true,
outfile: getPath(`../../exporter/index.${format === 'esm' ? 'm' : 'c'}js`),
platform: 'node',
external: ['typescript'],
banner:
format === 'esm'
? {
js: `
import { createRequire } from 'module'
global.require = createRequire(import.meta.url)`,
}
: {},
format,
sourcemap: watch,
tsconfig: './tsconfig.json',
}),
),
)
for (const ctx of contexts) {
if (watch) {
await ctx.watch()
console.info('👀 watching for changes...')
process.on('exit', async () => {
console.info('🙈 process killed')
await ctx.dispose()
})
} else {
await ctx.rebuild()
console.info('✅ build complete')
await ctx.dispose()
}
}