-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathesbuild.config.js
More file actions
45 lines (39 loc) · 1.08 KB
/
esbuild.config.js
File metadata and controls
45 lines (39 loc) · 1.08 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
const esbuild = require('esbuild')
const globby = require('globby')
const rimraf = require('rimraf')
// Automatically exclude all node_modules from the bundled version
const { nodeExternalsPlugin } = require('esbuild-node-externals')
const exit = (err) => {
console.error(err)
process.exit(1)
}
const removeExistingBuildOutput = async () => {
return new Promise((resolve, reject) => {
rimraf('./lib', (err) => {
if (err) return reject(err)
resolve()
})
})
}
const findSourceFiles = async () => globby('./src/**/*.ts')
const build = async files => {
console.log(`starting esbuild with ${files.length} source files.`)
console.time('build finished in')
return esbuild.build({
entryPoints: files,
format: 'cjs',
outdir: 'lib',
// bundle & minify output file
bundle: false,
minify: true,
platform: 'node',
sourcemap: true,
target: 'node14',
plugins: [nodeExternalsPlugin()]
})
}
removeExistingBuildOutput()
.then(findSourceFiles)
.then(build)
.then(() => console.timeEnd('build finished in'))
.catch(err => exit(err))