This repository was archived by the owner on Jul 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.js
More file actions
54 lines (50 loc) · 1.98 KB
/
esbuild.js
File metadata and controls
54 lines (50 loc) · 1.98 KB
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
const childProcess = require('child_process');
const packageJson = require('./package.json');
const makeAllPackagesExternalPlugin = {
name: 'make-all-packages-external',
setup(build) {
build.onResolve({filter: /\$[A-Za-z]+/}, () => ({external: false}))
build.onResolve({filter: /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/}, args => ({path: args.path, external: true}))
},
}
const args = require('args-parser')(process.argv);
let builded;
require('esbuild').build({
entryPoints: ['src/index.ts'],
outfile: 'build/index.js',
bundle: true,
plugins: [makeAllPackagesExternalPlugin],
platform: 'node',
define: {
'config.version': `"${packageJson.version}"`,
'config.commitHash': `"${childProcess.execSync('git rev-parse HEAD').toString().trim()}"`,
'config.commitCount': `${childProcess.execSync('git rev-list --count HEAD').toString().trim()}`,
'config.buildDate': `"${new Date().toISOString()}"`,
'config.port': args.dev ? '3005' : '80',
'config.dev': `${args.dev}`,
},
...(args.dev ? {
watch: {
onRebuild(error) {
if (error) console.error('⚠ watch build failed:', error)
else {
for (let i = 0; i < process.stdout.rows; i++) console.log('');
process.stdout.cursorTo(0, 0);
console.log('✔ Build successful.')
console.log('⚡ Restarting server...')
if (builded) builded.kill();
builded = childProcess.spawn('node', ['build/index.js'], {stdio: 'inherit'});
}
},
}
} : {}),
}).then(() => {
if (args.dev) {
for (let i = 0; i < process.stdout.rows; i++) console.log('');
process.stdout.cursorTo(0, 0);
console.log('⚡ Starting server...')
builded = childProcess.spawn('node', ['build/index.js'], {stdio: 'inherit'});
} else {
console.log('✔ Build successful.')
}
})