Explore use of script[type="importmap"] for libraries

Created on 17 March 2024, 8 months ago
Updated 3 July 2024, 4 months ago

Problem/Motivation

Importmaps are javascript files that list exports to load bundled modules.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/im...

I am thinking that using import maps might be a better solution than using libraries. Vite would compile all your libraries into an importmap and we could use this instead of referring to package.json. Your main library would just include the import map.

There are some experimental modules for this:
* https://www.drupal.org/project/importmap β†’
* https://www.drupal.org/project/importmaps β†’

Here's the relevant core issue: https://www.drupal.org/project/drupal/issues/3398525 ✨ Add an API for importmaps Active

This is a way to get more compatibility with code that is using js modules across Drupal. Maybe we can get the ball rolling at the theme level with vite since it can already be configured to set it up.

🌱 Plan
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mortona2k
  • πŸ‡¦πŸ‡ΊAustralia darvanen Sydney, Australia

    If this does happen I would really like it to be a configurable option. If a module/theme/whatever has a dependency with many levels of sub-dependencies, the cascading imports will be an unacceptable performance burden in my opinion.

Production build 0.71.5 2024