Coverage for webapp/vite_integration/impl/dev.py: 100%
15 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-17 22:07 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-17 22:07 +0000
1from typing import List
2from urllib.parse import urljoin
4from webapp.config import VITE_PORT
5from webapp.vite_integration.impl.base import _AbstractViteIntegration
8class DevViteIntegration(_AbstractViteIntegration):
9 def __init__(self):
10 self.baseurl = f"http://localhost:{VITE_PORT}/"
12 def get_dev_tools(self) -> str:
13 # Vite dev server integration needs 2 things:
14 # 1. the Vite client code for hot reload
15 # 2. the @react-refresh preamble
16 return (
17 ""
18 "<script"
19 ' type="module" '
20 f' src="{urljoin(self.baseurl, "@vite/client")}">'
21 "</script>"
22 '<script type="module">'
23 " import RefreshRuntime from "
24 f' "{urljoin(self.baseurl, "@react-refresh")}";'
25 " RefreshRuntime.injectIntoGlobalHook(window);"
26 " window.$RefreshReg$ = () => {};"
27 " window.$RefreshSig$ = () => (type) => type;"
28 " window.__vite_plugin_react_preamble_installed__ = true;"
29 "</script>"
30 )
32 def get_asset_url(self, asset_name: str) -> str:
33 # only return the requested entry point, Vite dev server will take
34 # care of the rest
35 return urljoin(self.baseurl, asset_name)
37 def get_imported_chunks(self, asset_name: str) -> List[str]:
38 # no need for this, Vite dev server imports automatically
39 return []
41 def get_imported_css(self, asset_name: str) -> List[str]:
42 # no need for this, Vite dev server imports automatically
43 return []