generated from project-error/npwd-app-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.js
37 lines (31 loc) · 921 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
const esbuild = require('esbuild');
const production = process.argv.findIndex(argItem => argItem === '--mode=production') >= 0;
const onRebuild = (context) => {
return async (err, res) => {
if (err) {
return console.error(`[${context}]: Rebuild failed`, err);
}
console.log(`[${context}]: Rebuild succeeded, warnings:`, res.warnings);
}
}
const server = {
platform: 'node',
target: ['node16'],
format: 'cjs',
};
const client = {
platform: 'browser',
target: ['chrome93'],
format: 'iife',
};
for (const context of [ 'client', 'server' ]) {
esbuild.build({
bundle: true,
entryPoints: [`${context}/${context}.ts`],
outfile: `dist/${context}.js`,
watch: production ? false : {
onRebuild: onRebuild(context),
},
...(context === 'client' ? client : server),
}).then(() => console.log(`[${context}]: Built successfully!`)).catch(() => process.exit(1));
}