@@ -26,7 +26,7 @@ def __init__(self, static_dir: str, settings: FrontendSettings):
2626 self .manifest_path = self .static_dir / "dist" / ".vite" / "manifest.json"
2727
2828 @lru_cache (maxsize = 1 ) # noqa: B019
29- def load_manifest (self ) -> dict :
29+ def load_manifest (self ) -> dict [ str , str ] :
3030 """Load Vite manifest (cached in production)."""
3131 if self .manifest_path .exists ():
3232 with self .manifest_path .open () as f :
@@ -43,7 +43,10 @@ def is_development(self) -> bool:
4343
4444 def get_asset_url (self , entry_name : str ) -> str | None :
4545 """
46- Get asset URL for entry (main, theme-switcher, etc).
46+ Get asset URL for entry (main, theme-switcher, prism-init, etc).
47+
48+ Dynamically discovers entries from manifest.json (production) or
49+ constructs paths for Vite dev server (development).
4750
4851 Args:
4952 entry_name: Entry name from vite.config.js
@@ -52,25 +55,20 @@ def get_asset_url(self, entry_name: str) -> str | None:
5255 Asset URL (dev server or production URL with hash)
5356 """
5457 if self .is_development () and self .settings .enable_vite_dev :
55- # Development: proxy to Vite server
56- entry_map = {
57- "main" : "frontend/js/main.js" ,
58- "theme-switcher" : "frontend/js/theme-switcher.js" ,
59- }
60- path = entry_map .get (entry_name )
61- if path :
62- return f"{ self .settings .vite_dev_server } /{ path } "
63- else :
64- # Production: use manifest
65- manifest = self .load_manifest ()
66- entry_map = {
67- "main" : "frontend/js/main.js" ,
68- "theme-switcher" : "frontend/js/theme-switcher.js" ,
69- }
70- input_path = entry_map .get (entry_name )
71- if input_path and input_path in manifest :
72- file_path = manifest [input_path ]["file" ]
58+ # Development: construct path dynamically for Vite dev server
59+ path = f"frontend/js/{ entry_name } .js"
60+ return f"{ self .settings .vite_dev_server } /{ path } "
61+
62+ # Production: dynamically search manifest for matching entry
63+ manifest = self .load_manifest ()
64+
65+ # Look for entry by name in manifest
66+ for entry_data in manifest .values ():
67+ # Check if this is an entry point with matching name
68+ if entry_data .get ("isEntry" ) and entry_data .get ("name" ) == entry_name :
69+ file_path = entry_data ["file" ]
7370 return f"{ self .settings .static_url_prefix } /{ file_path } "
71+
7472 return None
7573
7674 def get_css_url (self , entry_name : str ) -> str | None :
0 commit comments