Sha256: e132131552656b58da4aa1f767b560eb48d8d5d68f7ff589b7bd40e2c00dade0
Contents?: true
Size: 987 Bytes
Versions: 6
Compression:
Stored size: 987 Bytes
Contents
// FIXME: es-module-shim won't shim the dynamic import without this explicit import import "@hotwired/stimulus" export function registerControllersFrom(under, application) { const paths = Object.keys(parseImportmapJson()) .filter(path => path.match(new RegExp(`^${under}/.*_controller$`))) paths.forEach(path => registerControllerFromPath(path, under, application)) } export function parseImportmapJson() { return JSON.parse(document.querySelector("script[type=importmap]").text).imports } function registerControllerFromPath(path, under, application) { const name = path .replace(new RegExp(`^${under}/`), "") .replace("_controller", "") .replace(/\//g, "--") .replace(/_/g, "-") import(path) .then(module => application.register(name, module.default)) .catch(error => console.log(`Failed to register controller: ${name} (${path})`, error)) } console.warn("stimulus-importmap-autoload.js has been deprecated in favor of stimulus-loading.js")
Version data entries
6 entries across 6 versions & 1 rubygems