Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Varbase FAQs 9.2.1 Minor update available for module varbase_faqs (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

Importmaps

9 sites Security covered
View on drupal.org

This module provides an API for import maps, allowing you to bundle your JavaScript and treat third-party dependencies as naked imports that browsers can understand. It adds a necessary script tag to the page and enables modules to declare how other modules should be resolved.

Note

There is another module that provides similar functionality to this: Importmap module.

Features it includes above this module:

  • Support for scoped imports (scopes key in the importmap JSON)
  • Invalidating browser cache when the JS files are upadted (similar to what core does)
  • Optionally generate
    tags for modules in the importmap (this can help the browser parallelize requests, especially with long import chains)

It is hoped there will be a solution for this in Drupal core from 10.3 - please see the core issue.

If using this module please be aware that the API for this in core will likely be different.

Introduction

Provides an API for Import maps in Drupal.

Import maps allow you to bundle your JavaScript and exclude third-party dependencies, leaving them as naked imports.

e.g.

import React from 'react';

Ordinarily the browser can't understand that.
With an import map it can.

You can only have one <script type="importmap"></script> in the page, and that's where this module comes in.

Features

Adds a <script type="importmap"> element to the page.
Allows modules to declare how to resolve (import) modules.

Post-Installation

If you need to provide an import map, add a yourmodule.importmaps.yml file to the root of your module.
It should look like this

someRelativeEsModule:
  path: relative/path/to/your/file.js
someAbsoluteEsModule:
  path: /some/path/from/the/drupal/root/to/your/file.js

This would then allow your bundled code to look like so

import Something from "someRelativeEsModule"
import AnotherThing from "someAbsoluteEsModule"

The React module makes use of this functionality.

A note on bundling

If you want to make use of importmaps, you probably want to use something like Vite/Rollup externals e,g

// vite.config.ts
defineConfig({
   // other stuff
  build: {
    rollupOptions: {
        external: ["react", "react-dom", "react/jsx-runtime"],
      },
  },
  // more other stuff
})

Webpack has a similar functionality

Activity

Total releases
1
First release
Jul 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Dormant

Releases

Version Type Release date
1.0.0-alpha2 Pre-release Jul 1, 2025