-
Notifications
You must be signed in to change notification settings - Fork 34
/
esbuild.mjs
92 lines (81 loc) · 1.74 KB
/
esbuild.mjs
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import {umdWrapper} from 'esbuild-plugin-umd-wrapper';
import {build} from '../../scripts/esbuild/build.mjs';
import {apacheLicense} from '../../scripts/license/apache.mjs';
const devMode = process.argv[2] === 'dev';
/**
* @type {import('esbuild').BuildOptions}
*/
const base = {
entryPoints: ['src/index.ts'],
bundle: true,
banner: {js: apacheLicense()},
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
};
function nodeCjs() {
return build({
...base,
platform: 'node',
outfile: 'dist/bueno.js',
format: 'cjs',
});
}
function nodeEsm() {
return build({
...base,
platform: 'node',
outfile: 'dist/bueno.esm.js',
format: 'esm',
});
}
function browserEsm() {
return build({
...base,
platform: 'browser',
outfile: 'dist/browser/bueno.esm.js',
format: 'esm',
watch: devMode,
});
}
function browserEsmForAtomicDevelopment() {
const buildAtomic = build({
...base,
platform: 'browser',
outfile: '../atomic/src/external-builds/bueno.esm.js',
format: 'esm',
watch: devMode,
minify: false,
});
const buildHeadless = build({
...base,
platform: 'browser',
outfile: '../headless/src/external-builds/bueno.esm.js',
format: 'esm',
watch: devMode,
minify: false,
});
return Promise.all([buildAtomic, buildHeadless]);
}
function browserUmd() {
return build({
...base,
platform: 'browser',
outfile: 'dist/browser/bueno.js',
format: 'cjs',
banner: {
js: `${base.banner.js}`,
},
plugins: [umdWrapper({libraryName: 'Bueno'})],
});
}
async function main() {
await Promise.all([
nodeCjs(),
nodeEsm(),
browserEsm(),
browserUmd(),
browserEsmForAtomicDevelopment(),
]);
}
main();