Assets

Stimulus And Turbo Imports

Use GoLazy directives to import Hotwire libraries from app JavaScript.

By Guillermo Alvarez - Published - Updated

Declare the libraries

js.toml declares browser libraries as entrypoints:

[entrypoint.turbo]
module = "@hotwired/turbo"

[entrypoint.stimulus]
module = "@hotwired/stimulus"

lazy js installs and bundles these modules into public lazyshaft assets.

Use source directives

The application entry can stay small:

// golazy:turbo
// golazy:stimulus

// golazy:turbo expands to:

import "@hotwired/turbo"

// golazy:stimulus imports Stimulus, starts the application, and registers controllers found under app/js/controllers.

Load from the layout

Inline the generated importmap before importing the app entry:

{{importmap "/assets/importmap.json"}}
<script type="module">import "/js/app.js"</script>

The template uses stable import names. The importmap points browsers at the fingerprinted generated files.