MCPcopy
hub / github.com/vitejs/vite / warmupFile

Function warmupFile

packages/vite/src/node/server/warmup.ts:22–53  ·  view source on GitHub ↗
(
  server: ViteDevServer,
  environment: DevEnvironment,
  file: string,
)

Source from the content-addressed store, hash-verified

20}
21
22async function warmupFile(
23 server: ViteDevServer,
24 environment: DevEnvironment,
25 file: string,
26) {
27 // transform html with the `transformIndexHtml` hook as Vite internals would
28 // pre-transform the imported JS modules linked. this may cause `transformIndexHtml`
29 // plugins to be executed twice, but that's probably fine.
30 if (file.endsWith('.html')) {
31 const url = htmlFileToUrl(file, server.config.root)
32 if (url) {
33 try {
34 const html = await fs.readFile(file, 'utf-8')
35 await server.transformIndexHtml(url, html)
36 } catch (e) {
37 // Unexpected error, log the issue but avoid an unhandled exception
38 environment.logger.error(
39 `Pre-transform error (${colors.cyan(file)}): ${e.message}`,
40 {
41 error: e,
42 timestamp: true,
43 },
44 )
45 }
46 }
47 }
48 // for other files, pass it through `transformRequest` with warmup
49 else {
50 const url = fileToUrl(file, server.config.root)
51 await environment.warmupRequest(url)
52 }
53}
54
55function htmlFileToUrl(file: string, root: string) {
56 const url = path.relative(root, file)

Callers 1

warmupFilesFunction · 0.85

Calls 5

htmlFileToUrlFunction · 0.85
transformIndexHtmlMethod · 0.80
fileToUrlFunction · 0.70
errorMethod · 0.65
warmupRequestMethod · 0.65

Tested by

no test coverage detected