-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
46 lines (41 loc) · 1.03 KB
/
build.ts
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
import { build, Format } from 'esbuild';
import * as path from 'path';
const formats: Format[] = ['cjs', 'esm'];
/**
* Returns output filename with desired format
*/
function getOutputFilename(filename: string, format: Format) {
switch (format) {
case 'esm':
return `${filename}.mjs`;
default:
return `${filename}.js`;
}
}
/**
* Builds each entrypoint
*/
async function createBuild() {
for (const format of formats) {
const entryPoint = 'index';
const outputFilename = getOutputFilename(entryPoint, format);
try {
await build({
entryPoints: [path.resolve(__dirname, `./src/${entryPoint}.ts`)],
bundle: true,
minify: true,
platform: 'node',
loader: {
'.ts': 'ts',
},
outfile: path.resolve(__dirname, './dist/', outputFilename),
format,
});
console.info(`— ${outputFilename} was built`);
} catch (e) {
console.info(`🚨 ${outputFilename} build error:`);
console.error(e);
}
}
}
createBuild();