Sha256: d7121902cd56da75cc6d4bf0ea5a69da13c71b873e0724d2be5afb07d42a8697

Contents?: true

Size: 604 Bytes

Versions: 1

Compression:

Stored size: 604 Bytes

Contents

import { Application } from "@hotwired/stimulus"

const application = Application.start()

const importmap = 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

1 entries across 1 versions & 1 rubygems

Version Path
stimulus-rails-0.3.7 app/assets/javascripts/stimulus-importmap-autoloader.js