Skip to content

Need to add a way for initializing libraries that were just imported #1

@crimson-knight

Description

@crimson-knight

Let's say you're using a library like StimulusJS which requires that the application be initialized and then needs controllers mapped into the main application.

<script type="importmap">
  { 
    "imports": 
    {
      "@hotwired/stimulus": "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js",
      "HomeFlowController": "/home_controller.js" 
    }
  }
</script>
<script type="module">
  import { Application, Controller } from "@hotwired/stimulus"
  import HomeController from "HomeController"

  window.Stimulus = Application.start()

  Stimulus.register("home", HomeController)
</script>

Currently the import map tag is rendered by itself, and then you need to create a separate <script type="module"> to then initialize the JS. This is a bit cumbersome and because it's detached from the import map that's generated. The natural flow feels like the module script tag should be able to be generated from within the configuration block for the AssetPipeline and then the js files that are being pinned can be referenced in the import statements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions