Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
crimson-knight opened this issue Aug 16, 2024 · 0 comments

Comments

@crimson-knight
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant