-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.mjs
35 lines (31 loc) · 932 Bytes
/
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
/*global console*/
/*global process*/
import esbuild from 'esbuild';
import fs from 'node:fs';
let result = await esbuild.build({
entryPoints: ['src/index.mts', 'src/cleanup.mts'],
tsconfig: 'tsconfig.json',
define: {
"process.env.NODE_ENV": "\"production\""
},
bundle: true,
minify: true,
metafile : true,
outExtension: { '.js': '.mjs' },
platform: 'node',
format: 'esm',
target: 'node20.0',
outdir: './dist/',
treeShaking: true,
inject: ['src/cjs-shim.ts']
});
// Analyze the generate file size contributions
if (process.env.SHOW_ANALYSIS === '1' || process.env.SHOW_ANALYSIS === 'true') {
const meta = await esbuild.analyzeMetafile(result.metafile, {
verbose: false,
});
console.log(meta.replace(/.+\/cache/g,''));
}
if (process.env.CREATE_METAFILE === '1' || process.env.CREATE_METAFILE === 'true') {
fs.writeFileSync('dist/meta.json', JSON.stringify(result.metafile, null, 2));
}