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

Function hmr

packages/vite/src/node/server/hmr.ts:617–655  ·  view source on GitHub ↗
(environment: DevEnvironment)

Source from the content-addressed store, hash-verified

615 }
616
617 async function hmr(environment: DevEnvironment) {
618 try {
619 const { options, error } = hotMap.get(environment)!
620 if (error) {
621 throw error
622 }
623 if (!options.modules.length) {
624 // html file cannot be hot updated
625 if (file.endsWith('.html') && environment.name === 'client') {
626 environment.logger.info(
627 colors.green(`page reload `) + colors.dim(shortFile),
628 {
629 clear: true,
630 timestamp: true,
631 },
632 )
633 environment.hot.send({
634 type: 'full-reload',
635 path: config.server.middlewareMode
636 ? '*'
637 : '/' + normalizePath(path.relative(config.root, file)),
638 })
639 } else {
640 // loaded but not in the module graph, probably not js
641 debugHmr?.(
642 `(${environment.name}) [no modules matched] ${colors.dim(shortFile)}`,
643 )
644 }
645 return
646 }
647
648 updateModules(environment, shortFile, options.modules, timestamp)
649 } catch (err) {
650 environment.hot.send({
651 type: 'error',
652 err: prepareError(err),
653 })
654 }
655 }
656
657 const hotUpdateEnvironments =
658 server.config.server.hotUpdateEnvironments ??

Callers 1

handleHMRUpdateFunction · 0.70

Calls 6

normalizePathFunction · 0.90
prepareErrorFunction · 0.90
updateModulesFunction · 0.85
infoMethod · 0.65
sendMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected