-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.js
57 lines (52 loc) · 1.22 KB
/
esbuild.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
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const pkg = require(path.resolve('./package.json'));
const glob = require('glob');
const esbuild = require('esbuild');
const { argv } = require('process');
async function getFiles(pattern) {
return new Promise((resolve, reject) => {
glob(pattern, (err, res) => {
if (err) {
reject(err);
} else {
resolve(res);
}
});
});
}
async function buildBundle(entry, outfile, options) {
const external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
];
await esbuild.build({
entryPoints: [entry],
external,
bundle: true,
outfile,
minify: true,
sourcemap: true,
target: ['esnext'],
...options
});
}
async function buildFiles(globPattern, outdir, options) {
const files = await getFiles(globPattern);
await esbuild.build({
entryPoints: files,
bundle: false,
outdir,
minify: true,
sourcemap: true,
target: ['esnext'],
...options
});
}
buildBundle('src/index.ts', 'build/index.js', {
format: 'cjs',
});
buildBundle('src/index.ts', 'build/index.esm.js', {
format: 'esm',
});