-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview.js
More file actions
39 lines (34 loc) · 1.02 KB
/
Copy pathpreview.js
File metadata and controls
39 lines (34 loc) · 1.02 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
import { createServer } from "vite"
import { fileURLToPath } from "url"
import { dirname, join } from "path"
import { existsSync } from "fs"
const __dirname = dirname(fileURLToPath(import.meta.url))
const distDir = join(__dirname, "dist")
if (!existsSync(distDir)) {
console.error('❌ dist folder not found! Run "pnpm run build" first.')
process.exit(1)
}
const server = await createServer({
root: distDir,
server: {
port: 3000,
open: true
},
configureServer(server) {
server.middlewares.use((req, res, next) => {
console.log(`📄 ${req.method} ${req.url}`)
next()
})
}
})
await server.listen()
console.log("")
console.log("🚀 Preview server started!")
console.log("")
console.log(" Local: http://localhost:3000")
console.log("")
console.log(" Test your projects at:")
console.log(" - http://localhost:3000/ (index page)")
console.log(" - http://localhost:3000/<date>/<project-name>")
console.log("")
console.log("Press Ctrl+C to stop")