-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathdev.ts
78 lines (70 loc) · 1.7 KB
/
dev.ts
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import type * as Vite from "vite";
import colors from "picocolors";
import { preloadVite, getVite } from "./vite";
import * as profiler from "./profiler";
export interface ViteDevOptions {
clearScreen?: boolean;
config?: string;
cors?: boolean;
force?: boolean;
host?: boolean | string;
logLevel?: Vite.LogLevel;
mode?: string;
open?: boolean | string;
port?: number;
strictPort?: boolean;
profile?: boolean;
}
export async function dev(
root: string,
{
clearScreen,
config: configFile,
cors,
force,
host,
logLevel,
mode,
open,
port,
strictPort,
}: ViteDevOptions
) {
// Ensure Vite's ESM build is preloaded at the start of the process
// so it can be accessed synchronously via `getVite`
await preloadVite();
let vite = getVite();
let server = await vite.createServer({
root,
mode,
configFile,
server: { open, cors, host, port, strictPort },
optimizeDeps: { force },
clearScreen,
logLevel,
});
if (!server.config.plugins.find((plugin) => plugin.name === "react-router")) {
console.error(
colors.red("React Router Vite plugin not found in Vite config")
);
process.exit(1);
}
await server.listen();
server.printUrls();
let customShortcuts: Vite.CLIShortcut<typeof server>[] = [
{
key: "p",
description: "start/stop the profiler",
async action(server) {
if (profiler.getSession()) {
await profiler.stop(server.config.logger.info);
} else {
await profiler.start(() => {
server.config.logger.info("Profiler started");
});
}
},
},
];
server.bindCLIShortcuts({ print: true, customShortcuts });
}