PHPackages                             alto/importmap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. alto/importmap

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

alto/importmap
==============

Manage render and resolve Import Maps - Support scopes, integrity hashes, and WICG-compliant resolution.

v1.0.0(6mo ago)25MITPHPPHP &gt;=8.3CI passing

Since Dec 24Pushed 6mo agoCompare

[ Source](https://github.com/PhpAlto/importmap)[ Packagist](https://packagist.org/packages/alto/importmap)[ Docs](https://github.com/phpalto/importmap)[ GitHub Sponsors](https://github.com/sponsors/smnandre)[ RSS](/packages/alto-importmap/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Alto ImportMap
==============

[](#alto-importmap)

Alto ImportMap is a PHP library to build, validate, and render [import maps](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap)in PHP for web applications. It supports imports, scopes and integrity metadata, and includes a resolver aligned with the WICG resolution algorithm.

Installation
------------

[](#installation)

```
composer require alto/importmap
```

Basic Usage
-----------

[](#basic-usage)

### 1. Create an ImportMap

[](#1-create-an-importmap)

You can build an `ImportMap` manually or by adding entries.

```
use Alto\ImportMap\ImportMap;

$map = new ImportMap();

// Add a simple mapping
$map->add('react', 'https://esm.sh/react@18.2.0');
$map->add('react-dom', 'https://esm.sh/react-dom@18.2.0');
```

### 2. Load from File (Optional)

[](#2-load-from-file-optional)

You can also load an existing import map from a JSON file.

```
$map = ImportMap::fromFile(__DIR__ . '/importmap.json');

// You can still add entries dynamically
$map->add('app', '/js/app.js');
```

### 3. Render to HTML

[](#3-render-to-html)

Use the `HtmlRenderer` to generate the `` tag. It also supports `modulepreload` links for performance.

```
use Alto\ImportMap\Renderer\HtmlRenderer;

$renderer = new HtmlRenderer();

// Render the import map script and preload links
echo $renderer->render($map);
```

**Output:**

```

    {"imports":{"react":"https:\/\/esm.sh\/react@18.2.0","react-dom":"https:\/\/esm.sh\/react-dom@18.2.0"}}

```

Advanced Features
-----------------

[](#advanced-features)

### Scoped Imports

[](#scoped-imports)

You can define imports that only apply to specific scopes (paths).

```
// Available globally
$map->add('lodash', 'https://unpkg.com/lodash-es@4.17.21/lodash.js');

// Different version for a specific scope
$map->add(
    'lodash',
    'https://unpkg.com/lodash-es@3.10.1/lodash.js',
    scope: '/legacy/'
);
```

### Integrity Hashes

[](#integrity-hashes)

Ensure security by adding integrity hashes (SRI) to your entries. The renderer includes these in the import map. The `Resolver` can also use them, and you can access them via the `$map->integrity` property if needed for other tags.

```
$map->add(
    'app',
    '/js/app.js',
    integrity: 'sha384-...'
);
```

### Merging Maps

[](#merging-maps)

You can combine multiple maps, which is useful for modular applications.

```
$coreMap = new ImportMap(['react' => '...']);
$pluginMap = new ImportMap(['plugin-ui' => '...']);

$coreMap->merge($pluginMap);
```

### Resolving Imports

[](#resolving-imports)

The `NativeResolver` implements the [WICG Import Maps resolution algorithm](https://wicg.github.io/import-maps/#resolve-an-import-map-specifier). This allows you to resolve a specifier to a URL within your PHP application (e.g., for bundling or server-side rendering).

```
use Alto\ImportMap\Resolver\NativeResolver;

$resolver = new NativeResolver();

try {
    $resolution = $resolver->resolve('react', $map);
    // ['url' => 'https://esm.sh/react@18.2.0', 'integrity' => null]

    echo $resolution['url'];
} catch (ResolutionFailedException $e) {
    // Handle error
}
```

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

```
composer test
# or
vendor/bin/phpunit
```

### Static Analysis

[](#static-analysis)

```
composer analyse
# or
vendor/bin/phpstan analyse
```

### Code Formatting

[](#code-formatting)

```
vendor/bin/php-cs-fixer fix
```

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance67

Regular maintenance activity

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

191d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8951d49b371d210280a58ce48969a07d1f49924810f8a1fab3a9343eb46fdc9?d=identicon)[simonandre](/maintainers/simonandre)

---

Top Contributors

[![smnandre](https://avatars.githubusercontent.com/u/1359581?v=4)](https://github.com/smnandre "smnandre (1 commits)")

---

Tags

assetshtmlimportimport-mapimportmapintegritymodulespackagesscopephpjavascripthtmlmodulesrendererassetsImportmapesmwicg

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/alto-importmap/health.svg)

```
[![Health](https://phpackages.com/badges/alto-importmap/health.svg)](https://phpackages.com/packages/alto-importmap)
```

###  Alternatives

[efficiently/jquery-laravel

This package provides jQuery and the jQuery-ujs driver for your Laravel &gt;= 6 application.

1411.3k1](/packages/efficiently-jquery-laravel)[dorsetdigital/silverstripe-enhanced-requirements

Enhanced requirements for Silverstripe

118.4k4](/packages/dorsetdigital-silverstripe-enhanced-requirements)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
