-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
58 lines (53 loc) · 1.33 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const esbuild = require("esbuild");
const { watch } = require('chokidar');
let mode = process.env.NODE_ENV || 'development';
function prodBuild() {
esbuild.build({
entryPoints: ['./src/index.ts'],
bundle: true,
sourcemap : false,
target : "ES2015",
minify : true,
outfile: './dist/app.js',
tsconfig: './tsconfig.json'
})
.then(() => {
console.log("Built!")
process.exit(0)
})
.catch(() => {
console.log('Fail during build.')
process.exit(1)
});
}
function devBuild() {
esbuild.build({
entryPoints: ['./src/index.ts'],
bundle: true,
sourcemap : true,
target : "es2015",
minify : false,
outfile: './dist/app.js',
tsconfig: './tsconfig.json'
})
.then(() => console.log("Built!"))
.catch(() => {
console.log('Fail during build.')
process.exit(1)
});
}
if (mode === 'development') {
console.log('Development mode');
devBuild();
watch('./src/**/*.ts', {})
.on('change', () => {
if(mode === 'development') {
devBuild();
} else {
prodBuild();
}
});
} else {
console.log('Production mode');
prodBuild();
}