/
bundle.ts
56 lines (48 loc) · 1.24 KB
/
bundle.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
44
45
46
47
48
49
50
51
52
53
54
55
56
import { buildSync } from 'esbuild'
import glob from 'glob'
import { existsSync, rmSync, cpSync } from 'node:fs'
const { sync } = glob
console.log('Building dist for node (cjs)...')
// Generate entry-points for cjs compatibility
const localeDir = 'locale'
const target = ['ES2019', 'node14.17']
if (existsSync(localeDir)) {
rmSync(localeDir, { recursive: true, force: true })
}
buildSync({
entryPoints: sync('./src/**/*.ts'),
outdir: './dist/cjs',
bundle: false,
sourcemap: true,
minify: false,
format: 'cjs',
platform: 'node',
target,
})
console.log('Building dist for node type=module (esm)...')
buildSync({
entryPoints: ['./src/index.ts'],
outdir: './dist/esm',
bundle: true,
sourcemap: true,
minify: false,
splitting: false,
format: 'esm',
platform: 'node',
target,
outExtension: { '.js': '.mjs' },
external: ['k6/*', 'k6'],
})
console.log('Building dist for node type=module (cjs) but in esm dir...')
buildSync({
entryPoints: sync('./src/**/*.ts'),
outdir: './dist/esm',
bundle: false,
sourcemap: false,
minify: false,
format: 'cjs',
platform: 'node',
target,
})
cpSync('./src/k6-libs', './dist/esm/k6-libs', { recursive: true })
cpSync('./src/k6-libs', './dist/cjs/k6-libs', { recursive: true })