-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.js
48 lines (45 loc) · 981 Bytes
/
build.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
import esbuild from 'esbuild';
const watch = process.argv[2]?.includes('watch');
const __dirname = new URL('.', import.meta.url).pathname;
/** @type {esbuild.BuildOptions} */
const buildOptionsBase = {
platform: 'node',
entryPoints: [ `${__dirname}/src/index.ts` ],
bundle: true,
treeShaking: true,
minify: false,
absWorkingDir: __dirname,
outbase: `${__dirname}/src`,
outdir: `${__dirname}/dist`,
external: [
'@lapo/asn1js',
'rfc4648',
],
loader: {
'.ts': 'ts'
},
tsconfig: `${__dirname}/tsconfig.json`,
};
(async () => {
if (!watch) {
await esbuild.build({
...buildOptionsBase,
format: 'esm',
outExtension: { '.js': '.mjs' },
});
await esbuild.build({
...buildOptionsBase,
format: 'cjs',
outExtension: { '.js': '.cjs' },
});
console.log('done');
} else {
await esbuild.build({
...buildOptionsBase,
format: 'esm',
outExtension: { '.js': '.mjs' },
});
await context.watch();
console.log('watching...');
}
})();