Vite.View (vite_phx v0.3.2)

Help with View integration into Phoenix views

Link to this section Summary

Functions

Helper to generate HTML for a CSS link with static tracking

Helper to get HTML for all entry points at once

Generate all links for an entry struct in following order

Helper to generate inlined Phoenix cache manifest to simplify integration with Javascript code.

Helper to generate HTML for module preloading, eg

Helper to generate HTML for JS modules

The snippet for @vite/client during development. Does nothing in :prod env.

The complete snippet for a single entry-point during prod. Delegates to vite dev-server otherwise. See :for_entry for details.

Link to this section Functions

Link to this function

css_link(href, prefix)

Specs

css_link(binary(), binary()) :: binary()

Helper to generate HTML for a CSS link with static tracking:

<link phx-track-static rel="stylesheet" href="/some-styles.css"/>

Link to this function

for_entries(entries, prefix \\ "/")

Helper to get HTML for all entry points at once

Link to this function

for_entry(entry, prefix \\ "/")

Specs

for_entry(list(), binary()) :: binary()

Generate all links for an entry struct in following order:

  1. styles to prevent FOUC
  2. main entry script
  3. imports

<link phx-track-static rel="stylesheet" href="/assets/main.34asdfsf.css"/> <script type="module" crossorigin defer phx-track-static src="/assets/main.89abc777.js"></script> <link rel="modulepreload" href="/assets/_vendor.7788aaa.js">

Link to this function

inlined_phx_manifest()

Specs

inlined_phx_manifest() :: {atom(), binary()} | binary()

Helper to generate inlined Phoenix cache manifest to simplify integration with Javascript code.

The manifest generated by mix phx.digest is stored in a global variable window.PhxManifest. Only works in :prod environment.

Link to this function

module_preload(href, prefix)

Specs

module_preload(binary(), binary()) :: binary()

Helper to generate HTML for module preloading, eg:

<link rel="modulepreload" href="/a-module.js">

Link to this function

module_script(src, prefix)

Specs

module_script(binary(), binary()) :: binary()

Helper to generate HTML for JS modules

Has automatic inclusion of defer, crossorigin and phx-track-static attributes.

<script type="module" crossorigin defer phx-track-static src="/module.js"></script>

Specs

vite_client() :: binary() | {:safe, binary()}

The snippet for @vite/client during development. Does nothing in :prod env.

Link to this function

vite_snippet(entry_name)

Specs

vite_snippet(binary()) :: binary() | {:safe, binary()}

The complete snippet for a single entry-point during prod. Delegates to vite dev-server otherwise. See :for_entry for details.