-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mjs
executable file
·55 lines (49 loc) · 1.31 KB
/
build.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
#!/usr/bin/env -S node --experimental-json-modules --no-warnings
import { comment } from '@webdeveric/utils/comment';
import { build } from 'esbuild';
import { clean } from 'esbuild-plugin-clean';
import { environmentPlugin } from 'esbuild-plugin-environment';
import pkg from './package.json' with { type: 'json' };
try {
const results = await build({
entryPoints: ['./src/cli.ts'],
outdir: './dist',
platform: 'node',
bundle: true,
format: 'esm',
splitting: true,
outExtension: {
'.js': '.mjs',
},
packages: 'external',
target: `node${process.versions.node}`,
minify: process.env.NODE_ENV === 'production',
banner: {
js: comment(
`
@file ${pkg.name}
@version ${pkg.version}
@license ${pkg.license}
@copyright ${pkg.author.name} ${new Date().getFullYear()}
@see {@link ${pkg.homepage}}
`,
{
type: 'legal',
},
),
},
plugins: [
clean({
patterns: ['./dist/*'],
}),
environmentPlugin(['npm_package_name']),
],
});
const errors = [...results.warnings, ...results.errors];
if (errors.length) {
throw new AggregateError(errors, 'Build error and warnings');
}
} catch (error) {
console.error(error);
process.exitCode ||= 1;
}