-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
62 lines (46 loc) · 1.4 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
59
60
61
62
const path = require('path')
const fs = require('fs-extra')
const webpack = require('webpack')
const config = require('./webpack')
async function run() {
console.log('[ + ] Start compiling')
const stats = await compile()
console.log(
`[ + ] Webpack compile is complete in ${stats.time / 1000} seconds`.magenta
)
fs.copySync(
path.join(path.resolve(__dirname, './app'), 'static'),
path.join(path.resolve(__dirname, './dist'), 'static')
)
console.log('[ + ] Static assets are copied'.magenta)
}
function compile() {
const compiler = webpack(config)
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
if (err) {
console.trace('Run error', err.stack)
return reject(err)
}
const jsonStats = stats.toJson(true)
if (jsonStats.errors.length > 0) {
console.log('[ * ] Webpack compiler encountered errors.'.red)
jsonStats.errors.forEach(err => {
console.log(err)
})
return reject(new Error('Webpack compiler encountered errors'))
}
if (jsonStats.warnings.length > 0) {
console.log('[ ! ] Webpack compiler encountered warnings.'.yellow)
jsonStats.warnings.forEach(warning => {
console.log(warning.message)
})
}
return resolve(jsonStats)
})
})
}
run().catch(e => {
console.trace('error in build:', e)
process.exit(1)
})