glimr/vite

Vite Asset Integration

Glimr apps use Vite as their asset bundler, but templates need the correct script and link tags for both development (where Vite’s dev server handles HMR) and production (where hashed filenames come from a manifest). This module reads the Vite manifest and hot-file to emit the right tags automatically — like Laravel’s @vite() directive.

Types

A structured representation of a single HTML tag needed for a Vite entry point. Useful when you need to render tags in a typed UI library like Lustre instead of injecting raw HTML.

pub type Tag {
  Script(src: String)
  Stylesheet(href: String)
}

Constructors

  • Script(src: String)
  • Stylesheet(href: String)

Values

pub fn render_tags(tags: List(Tag)) -> String

Renders a list of tags to an HTML string. This is the building block behind tags() and can be used standalone when you have a List(Tag) from to_tags().

pub fn tags(entry: String) -> String

Emits the <script> and <link> tags for a Vite entry point as a ready-to-use HTML string.

In dev mode (when priv/static/hot exists), returns tags pointing at Vite’s dev server for HMR. In production, reads the Vite manifest to resolve hashed filenames and returns prebuilt asset tags with a /static/ prefix.

@import(glimr/vite)
{{{ vite.tags("resources/ts/app.ts") }}}
pub fn to_tags(entry: String) -> List(Tag)

Returns structured tag data for a Vite entry point. Each item in the list is either a Script or Stylesheet with the resolved URL. Use this when you need to map the tags into a typed element tree (e.g. Lustre) rather than injecting raw HTML.

vite.to_tags("src/resources/ts/app.ts")
|> list.map(fn(tag) {
  case tag {
    vite.Script(src) -> html.script([attribute.type_("module"), attribute.src(src)], [])
    vite.Stylesheet(href) -> html.link([attribute.rel("stylesheet"), attribute.href(href)])
  }
})
Search Document