-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathvite-node.ts
More file actions
29 lines (24 loc) · 705 Bytes
/
vite-node.ts
File metadata and controls
29 lines (24 loc) · 705 Bytes
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
import { createServer } from 'vite';
import { resolve } from 'path';
async function runScript(scriptPath: string) {
const absolutePath = resolve(scriptPath);
const server = await createServer({
configFile: './vite.config.js',
server: { middlewareMode: true },
});
try {
const module = await server.ssrLoadModule(absolutePath);
if (typeof module.main === 'function') {
await module.main();
} else {
console.error('No main function exported from', scriptPath);
}
} finally {
await server.close();
}
}
const scriptPath = process.argv[2];
runScript(scriptPath).catch((error) => {
console.error('Error running script:', error);
process.exit(1);
});