-
Notifications
You must be signed in to change notification settings - Fork 1
/
esbuild.config.js
63 lines (54 loc) · 1.54 KB
/
esbuild.config.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
const path = require('path')
const glob = require('glob')
const esbuild = require('esbuild')
const { dtsPlugin } = require('esbuild-plugin-d.ts')
const buildForCustomEnvironment = async ({
format = 'cjs',
...options
} = {}) => {
const entryPoints = glob.sync(path.join(process.cwd(), 'src/**/*.ts'))
const result = await esbuild.build({
entryPoints,
outdir: `dist/${format}`,
packages: 'external',
format,
platform: 'node',
target: ['node12'],
...options
})
console.log(`Build for ${format.toUpperCase()} 🚀`, result)
}
const buildForBrowser = async ({ output, entryPoint, ...options }) => {
const result = await esbuild.build({
entryPoints: [entryPoint],
bundle: true,
outfile: `dist/umd/${output}.min.js`,
minify: true,
globalName: `globalThis.${output}`,
platform: 'browser',
format: 'iife',
target: ['chrome58', 'edge18', 'firefox57', 'safari11', 'node12'],
...options
})
console.log('Build for Browser 🚀', result)
}
const init = async () => {
await buildForCustomEnvironment({ format: 'cjs', plugins: [dtsPlugin()] })
await buildForCustomEnvironment({ format: 'esm' })
await buildForCustomEnvironment({
format: 'esm',
outExtension: { '.js': '.mjs' },
plugins: [dtsPlugin()]
})
const allEntryPoints = [
{ output: 'killa', entryPoint: './src/core.ts' },
{
output: 'killaMiddlewares',
entryPoint: './src/middleware'
}
]
for (let i = 0; i < allEntryPoints.length; i++) {
await buildForBrowser(allEntryPoints[i])
}
}
init()