@@ -38,28 +38,28 @@ defmodule CodebattleWeb.Vite do
3838 end
3939
4040 def css_paths ( entry ) do
41+ m = manifest ( )
42+
4143 paths =
42- case manifest ( ) [ entry ] do
44+ case m [ entry ] do
4345 % { "css" => css_list } ->
44- # CSS imported by this JS entry
4546 Enum . map ( css_list , & ( "/assets/" <> & 1 ) )
4647
4748 _ ->
48- # No CSS imported by this entry, look for standalone CSS
49- # Try to find a CSS file that matches the JS entry name
50- # For "app.js", look for any entry that outputs "app.css"
51- css_filename = String . replace ( entry , ~r/ \. js$/ , ".css" )
52-
53- # Search through all manifest entries to find one with matching output
54- case Enum . find ( manifest ( ) , fn { _k , v } ->
55- is_map ( v ) && Map . get ( v , "file" ) == css_filename
56- end ) do
57- { _key , % { "file" => file } } -> [ "/assets/" <> file ]
58- _ -> [ ]
59- end
49+ find_standalone_css ( m , entry )
6050 end
6151
62- # Apply digest hash to all paths in production
6352 Enum . map ( paths , & apply_digest / 1 )
6453 end
54+
55+ defp find_standalone_css ( manifest_map , entry ) do
56+ css_filename = String . replace ( entry , ~r/ \. js$/ , ".css" )
57+
58+ case Enum . find ( manifest_map , fn { _k , v } ->
59+ is_map ( v ) && Map . get ( v , "file" ) == css_filename
60+ end ) do
61+ { _key , % { "file" => file } } -> [ "/assets/" <> file ]
62+ _ -> [ ]
63+ end
64+ end
6565end
0 commit comments