-
Notifications
You must be signed in to change notification settings - Fork 9
/
vite.js
43 lines (32 loc) · 883 Bytes
/
vite.js
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
const vite = require('vite');
module.exports.start = async (opts = {}) => {
const {createServer} = vite;
const options = Object.assign({
root: './',
base: '/',
mode: 'development',
configFile: '',
logLevel: 'info',
clearScreen: false
}, opts);
options.server = {
host: '0.0.0.0'
};
if (opts.server) {
options.server = Object.assign(options.server, opts.server);
}
try {
const server = await createServer(options);
if (!server.httpServer) {
throw new Error('HTTP server not available');
}
const port = await server.listen();
const info = server.config.logger.info;
info(`\n vite v${require('vite/package.json').version} dev server running at:\n`);
server.printUrls();
return server;
} catch (e) {
console.error(`error when starting dev server:\n${e.stack}`);
return e;
}
};