-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-server.js
More file actions
56 lines (48 loc) · 1.33 KB
/
dev-server.js
File metadata and controls
56 lines (48 loc) · 1.33 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
#!/usr/bin/env node
import { readFileSync } from 'fs'
import { spawn } from 'child_process'
// Parse .env file
const envFile = readFileSync('.env', 'utf8')
const envVars = {}
envFile.split('\n').forEach(line => {
const trimmed = line.trim()
if (trimmed && !trimmed.startsWith('#')) {
const [key, ...rest] = trimmed.split('=')
if (key && rest.length) envVars[key] = rest.join('=')
}
})
const proxy = envVars.DEV_URL || 'https://cds.ddev.site'
const port = envVars.BROWSERSYNC_PORT || '3000'
console.log('Starting development server...')
console.log(`Vite: Building assets in watch mode`)
console.log(`Browser-Sync: Proxying ${proxy} on port ${port}`)
// Start Vite build in watch mode
const vite = spawn('npx', ['vite', 'build', '--watch'], {
stdio: 'inherit',
})
// Start Browser-Sync
const browserSync = spawn('npx', ['browser-sync', 'start',
'--proxy', proxy,
'--https',
'--files', '**/*.php,dist/**/*.css,dist/**/*.js',
'--ignore', 'node_modules',
'--port', port,
'--reload-delay', '200',
], {
stdio: 'inherit',
env: {
...process.env,
NODE_TLS_REJECT_UNAUTHORIZED: '0',
NODE_NO_WARNINGS: '1',
},
})
process.on('SIGINT', () => {
vite.kill('SIGTERM')
browserSync.kill('SIGTERM')
process.exit(0)
})
process.on('SIGTERM', () => {
vite.kill('SIGTERM')
browserSync.kill('SIGTERM')
process.exit(0)
})