-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdev.js
91 lines (85 loc) · 1.83 KB
/
dev.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const child_process = require('child_process')
const fs = require('fs')
const kill = require('tree-kill')
// Clean build directory
const buildDir = process.env.MANIFEST_V3 === 'true' ? 'dist-v3' : 'dist'
if (fs.existsSync(buildDir)) {
fs.rmSync(buildDir, { recursive: true })
}
fs.mkdirSync(buildDir)
// Spawn vite for .config
const mainChild = child_process.spawn('npx', [
'vite',
'build',
'--config',
'vite.config.js',
'--watch',
'--mode',
'development'
], { stdio: 'inherit' })
const mainBuild = new Promise((res, rej) => {
mainChild.on('close', code => {
if (code !== 0) {
rej(code)
} else {
res()
}
})
})
// Spawn vite for .bg.config
const bgChild = child_process.spawn('npx', [
'vite',
'build',
'--config',
'vite.bg.config.js',
'--watch',
'--mode',
'development'
], { stdio: 'inherit' })
const bgBuild = new Promise((res, rej) => {
bgChild.on('close', code => {
if (code !== 0) {
rej(code)
} else {
res()
}
})
})
// Spawn vite for .content.config
const contentChild = child_process.spawn('npx', [
'vite',
'build',
'--config',
'vite.content.config.js',
'--watch',
'--mode',
'development'
], { stdio: 'inherit' })
const contentBuild = new Promise((res, rej) => {
contentChild.on('close', code => {
if (code !== 0) {
rej(code)
} else {
res()
}
})
})
// Kill all children on exit and ctrl-C
const killAllChildren = () => {
kill(mainChild.pid)
kill(bgChild.pid)
kill(contentChild.pid)
}
process.on('exit', killAllChildren)
process.on('SIGINT', killAllChildren)
// Wait for all builds to finish
Promise.all([mainBuild, bgBuild, contentBuild])
.then(() => {
console.log('All builds finished')
})
.catch((code) => {
if (code !== null) {
console.error(`Build failed with code ${code}`)
}
process.exit(code)
})