You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then the following module will be compiled according to the env thanks to Application.compile_env.
You get rid of unwanted code in production 👌
# Vite.exifApplication.compile_env!(:liveview_pwa,:env)==:proddodefmoduleVitedo@moduledoc""" A helper module to manage Vite file discovery. It proxies the static assets with "http://localhost:5173" in DEV mode. It finds the fingerprinted name in PROD mode from the ".vite/manifest.json" file generated by `Vite`. Phoenix will now be able to serve them. """# Ensure the manifest is loaded at compile time in productiondefpath(asset)domanifest=get_manifest()casePath.extname(asset)do".css"->get_main_css_in(manifest)_->get_name_in(manifest,asset)endenddefpget_manifestdomanifest_path=Path.join(:code.priv_dir(:liveview_pwa),"static/.vite/manifest.json")with{:ok,content}<-File.read(manifest_path),{:ok,decoded}<-Jason.decode(content)dodecodedelse_->raise"Could not read or decode Vite manifest at #{manifest_path}"endenddefget_main_css_in(manifest)domanifest|>Enum.flat_map(fn{_key,entry}->Map.get(entry,"css",[])end)|>Enum.filter(fnfile->String.contains?(file,"main")end)|>List.first()enddefget_name_in(manifest,asset)docasemanifest[asset]do%{"file"=>file}->"/#{file}"_->raise"Asset #{asset} not found in manifest"endendendelsedefmoduleVitedodefpath(asset)do"http://localhost:5173/#{asset}"endendend
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In my "config.exs", I get the
MIX_ENV:Then the following module will be compiled according to the
envthanks toApplication.compile_env.You get rid of unwanted code in production 👌
Beta Was this translation helpful? Give feedback.
All reactions