Sha256: c773b56cd75386273291da05b0dcb26a337f1a1945791c59965e017c6f48b411

Contents?: true

Size: 610 Bytes

Versions: 3

Compression:

Stored size: 610 Bytes

Contents

import { Application } from "@hotwired/stimulus"

const application = Application.start()

const importmap = await JSON.parse(document.querySelector("script[type=importmap]").text)
const importedControllerPaths = Object.keys(importmap.imports).filter((e) => e.match("controllers/"))

importedControllerPaths.forEach(function(path) {
  const name = path.replace("controllers/", "").replace("_controller", "").replace("/", "--").replace("_", "-")

  import(path)
    .then(module => application.register(name, module.default))
    .catch(error => console.log(`Failed to autoload controller: ${name}`, error))
})

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stimulus-rails-0.3.6 app/assets/javascripts/stimulus-importmap-autoloader.js
stimulus-rails-0.3.5 app/assets/javascripts/stimulus-importmap-autoloader.js
stimulus-rails-0.3.4 app/assets/javascripts/stimulus-importmap-autoloader.js