Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
76 lines (61 loc) · 1.49 KB
/
Copy pathindex.js
File metadata and controls
76 lines (61 loc) · 1.49 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const webpack = require('webpack')
class PwaRunner {
constructor () {
this.cswWatcher = null
}
init () {}
shouldAbort (quasarConfFile) {
return (
quasarConfFile.quasarConf.pwa.workboxPluginMode !== 'InjectManifest'
|| (quasarConfFile.quasarConf.ctx.mode.ssr === true && quasarConfFile.quasarConf.ctx.mode.pwa !== true)
)
}
async run (quasarConfFile) {
if (this.cswWatcher) {
await this.stop()
}
if (this.shouldAbort(quasarConfFile)) {
return
}
const cswCompiler = webpack(quasarConfFile.webpackConf.csw)
return new Promise(resolve => {
this.cswWatcher = cswCompiler.watch({}, async (err, stats) => {
if (err) {
console.log(err)
return
}
if (stats.hasErrors() === false) {
resolve()
}
})
})
}
build (quasarConfFile) {
if (this.shouldAbort(quasarConfFile)) {
return
}
return new Promise(resolve => {
webpack(quasarConfFile.webpackConf.csw, async (err, stats) => {
if (err) {
console.error(err.stack || err)
if (err.details) {
console.error(err.details)
}
process.exit(1)
}
if (stats.hasErrors() !== true) {
resolve()
}
})
})
}
stop () {
if (this.cswWatcher) {
return new Promise(resolve => {
this.cswWatcher.close(resolve)
this.cswWatcher = null
})
}
}
}
module.exports = new PwaRunner()