-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (31 loc) · 1.07 KB
/
server.js
File metadata and controls
37 lines (31 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
// import CommandLine from "../CommandLine";
const { createServer } = require('vite')
const { ViteNodeServer } = require('vite-node/server')
const { ViteNodeRunner } = require('vite-node/client')
async function Server() {
// create vite server
const server = await createServer()
// this is need to initialize the plugins
await server.pluginContainer.buildStart({})
// create vite-node server
const node = new ViteNodeServer(server)
// create vite-node runner
const runner = new ViteNodeRunner({
// root: server.config.root,
// base: server.config.base,
// when having the server and runner in a different context,
// you will need to handle the communication between them
// and pass to this function
fetchModule(id) {
return node.fetchModule(id)
},
resolveId(id, importer) {
return node.resolveId(id, importer)
},
})
// execute the file
await runner.executeFile('./app/index.ts')
// close the vite server
// await server.close()
}
Server();