-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev-server.js
More file actions
44 lines (36 loc) · 1.07 KB
/
dev-server.js
File metadata and controls
44 lines (36 loc) · 1.07 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
import { exec as callbackExec } from 'node:child_process'
import path from 'node:path'
import { promisify } from 'node:util'
import chokidar from 'chokidar'
import express from 'express'
const exec = promisify(callbackExec)
const buildScript = path.join(import.meta.dirname, 'scripts/build.sh')
function build() {
return exec(buildScript)
}
chokidar.watch(
[
'javascript/',
'resources/',
'index.js',
'index.template.html',
// Watch these files instead of trying to watch the entire node_modules folder
'package.json',
'package-lock.json'
].map(projectRelativePath => path.join(import.meta.dirname, projectRelativePath)),
{
ignored: /-definitions\.json$/, // Ignore the generated combined definition files
ignoreInitial: true
}
).on('all', () => {
console.log('Rebuilding assets')
build()
})
console.log('Building assets')
await build()
const app = express()
app.use('/', express.static(import.meta.dirname))
const port = process.env.PORT || 8080
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`)
})