Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Opensolr Search 4.5.0 Minor update available for module opensolr_search (4.5.0). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Importmaps

8 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

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

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

Releases

Version Type Core Release date
1.0.0-alpha2 Pre-release 9โ€“11 Jul 1, 2025