PhoenixVite.Components (Phoenix Vite v0.3.3)

View Source

Vite related components to be used within your phoenix application.

Usage

Put the following into your <head /> of your phoenix root layout:

<PhoenixVite.Components.assets
  names={["js/app.js", "css/app.css"]}
  manifest={{:my_app, "priv/static/.vite/manifest.json"}}
  dev_server={PhoenixVite.Components.has_vite_watcher?(MyAppWeb.Endpoint)}
/>

If you want to make use of the dev server you need to provide the to_url option.

<PhoenixVite.Components.assets
  names={["js/app.js", "css/app.css"]}
  manifest={{:my_app, "priv/static/.vite/manifest.json"}}
  dev_server={PhoenixVite.Components.has_vite_watcher?(MyAppWeb.Endpoint)}
  to_url={fn p -> static_url(@conn, p) end}
/>

This also requires having the static_url configured for the endpoint.

config :myapp, MyAppWeb.Endpoint,
  static_url: [host: "localhost", port: 5173]

Summary

Functions

Asset references of vite to be placed into the <head /> of a html page.

Asset references of vite dev server to be placed into the <head /> of a html page.

Asset references of vite manifest to be placed into the <head /> of a html page.

Manually clear the cache for a vite manifest source.

Checks for a conventional :vite key in the endpoints :watchers list.

Functions

assets(assigns)

Asset references of vite to be placed into the <head /> of a html page.

Switches between dev server provided resources or static resources based on a vite manifest file.

Attributes

  • names (:list) (required)
  • manifest (:any) (required)
  • to_url ({:fun, 1}) - Defaults to &Function.identity/1.
  • dev_server (:boolean) - Defaults to false.

assets_from_dev_server(assigns)

Asset references of vite dev server to be placed into the <head /> of a html page.

Attributes

  • names (:list) (required)
  • to_url ({:fun, 1}) - Defaults to &Function.identity/1.

assets_from_manifest(assigns)

Asset references of vite manifest to be placed into the <head /> of a html page.

Caches manifests at runtime when refernces require parsing per provided source.

Attributes

  • name (:string) (required)
  • manifest (:any) (required)
  • to_url ({:fun, 1}) - Defaults to &Function.identity/1.

clear_manifest_cache(manifest)

Manually clear the cache for a vite manifest source.

has_vite_watcher?(endpoint)

@spec has_vite_watcher?(phoenix_endpoint :: module()) :: boolean()

Checks for a conventional :vite key in the endpoints :watchers list.