# vite-plugin-shopify-import-maps

> Enhances Shopify theme development by adding support for import-maps

Latest version **0.7.4** (published 2026-06-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-shopify-import-maps
pnpm add vite-plugin-shopify-import-maps
yarn add vite-plugin-shopify-import-maps
bun add vite-plugin-shopify-import-maps
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.7.4 |
| Published | 2026-06-29 |
| First published | 2023-09-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 67.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | Slava M. <hi@slava.fyi> |
| Maintainers | slavafyi |
| Keywords | vite, plugin, shopify, import-maps, shopify-import-maps |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-shopify-import-maps
- Repository: https://github.com/slavafyi/vite-plugin-shopify-import-maps
- Homepage: https://github.com/slavafyi/vite-plugin-shopify-import-maps#readme
- Issues: https://github.com/slavafyi/vite-plugin-shopify-import-maps/issues
- npm.io page: https://npm.io/package/vite-plugin-shopify-import-maps

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.7.4 (latest) — 2026-06-29
- 0.7.3 — 2026-04-20
- 0.7.2 — 2026-03-15
- 0.7.1 — 2026-03-01
- 0.7.0 — 2026-01-20
- 0.6.1 — 2026-01-17
- 0.6.0 — 2026-01-17
- 0.5.4 — 2024-04-16
- 0.5.3 — 2024-04-06
- 0.5.2 — 2024-01-16
- 0.5.1 — 2024-01-16
- 0.5.0 — 2023-12-28
- 0.4.2 — 2023-12-28
- 0.4.0 — 2023-11-02
- 0.3.0 — 2023-10-31
- … 3 more at https://npm.io/package/vite-plugin-shopify-import-maps/versions

## README

[![npm](https://img.shields.io/npm/v/vite-plugin-shopify-import-maps?color=brightgreen)](https://www.npmjs.com/package/vite-plugin-shopify-import-maps) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Test](https://github.com/slavafyi/vite-plugin-shopify-import-maps/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/slavafyi/vite-plugin-shopify-import-maps/actions/workflows/test.yml)

# vite-plugin-shopify-import-maps

The `vite-plugin-shopify-import-maps` enhances Shopify theme development by adding support for [import-maps](https://github.com/WICG/import-maps) which can be used to control the resolution of module specifiers.

## Requirements

Before using this plugin, make sure you have the [vite-plugin-shopify](https://github.com/barrel/shopify-vite/tree/main/packages/vite-plugin-shopify) installed. This plugin provides the necessary underlying setup for developing Shopify themes with Vite.

## Install

```bash
npm i -D vite-plugin-shopify-import-maps

# yarn
yarn add -D vite-plugin-shopify-import-maps

# pnpm
pnpm add -D vite-plugin-shopify-import-maps
```

## Usage

1. Add [ES Module Shims](https://github.com/guybedford/es-module-shims#usage) to the `<head>` tag in your `theme.liquid` file.

2. Render the `importmap` snippet file **before** performing any imports:

```liquid
<script src="{{ 'es-module-shims.js' | asset_url }}" async></script>

{% liquid
  render 'importmap'
  render 'vite-tag' with 'theme.js'
  render 'vite-tag' with 'customers.js'
%}
```

3. Add the `vite-plugin-shopify-import-maps` to your `vite.config.js` file:

```js
import { defineConfig } from 'vite'
import shopify from 'vite-plugin-shopify'
import importMaps from 'vite-plugin-shopify-import-maps'

// Recommended configuration
export default defineConfig({
  build: {
    rollupOptions: {
      output: {
        entryFileNames: '[name].js',
        chunkFileNames: '[name].js',
        assetFileNames: '[name].[ext]'
      }
    }
  },
  plugins: [
    shopify({ versionNumbers: true }),
    importMaps({ bareModules: true })
  ]
})
```

After executing the build command, the `importmap.liquid` file will be generated in the `snippets` folder in your theme root directory.

## Options

### themeRoot

- **Type:** `string`
- **Default:** `'./'`

Root path to your Shopify theme directory.

### snippetFile

- **Type:** `string`
- **Default:** `'importmap.liquid'`

Specifies the file name of the snippet that include import map.

### bareModules

- **Type:** `boolean | BareModules`
- **Default:** `false`

```ts
export interface BareModules {
  defaultGroup: string
  groups: Record<string, string | RegExp | Array<string | RegExp>>
}
```

Configure bare specifier remapping for JavaScript modules.

Example:

```ts
export default defineConfig({
  plugins: [
    importMap({
      bareModules: {
        defaultGroup: 'main', // By default is 'main'
        groups: {
          helpers: /frontend\/lib/, // RegExp pattern
          vendors: 'node_modules', // String
          general: ['frontend/entrypoints', /vite/] // Array of string or RegExp pattern
        }
      }
    })
  ]
})
```

This generates the `importmap.liquid` file:

```liquid
<script type="importmap">
{
  "imports": {
    "general/customers": "{{ 'customers.js' | asset_url }}",
    "general/modulepreload-polyfill": "{{ 'modulepreload-polyfill.js' | asset_url }}",
    "general/theme": "{{ 'theme.js' | asset_url }}",
    "helpers/customer-address": "{{ 'customer-address.js' | asset_url }}",
    "helpers/shopify_common": "{{ 'shopify_common.js' | asset_url }}",
    "helpers/utils": "{{ 'utils.js' | asset_url }}",
    "main/header-drawer": "{{ 'header-drawer.js' | asset_url }}",
    "main/localization-form": "{{ 'localization-form.js' | asset_url }}",
    "main/product-recommendations": "{{ 'product-recommendations.js' | asset_url }}",
    "vendors/lodash": "{{ 'lodash.js' | asset_url }}"
  }
}
</script>
```

### modulePreload

- **Type:** `boolean`
- **Default:** `false`

This option when set to `true`, generates `modulepreload` link tags below the import map script tag.

```liquid
<link rel="modulepreload" href="{{ 'customers.js' | asset_url }}">
<link rel="modulepreload" href="{{ 'theme.js' | asset_url }}">
```

## Troubleshooting

If you have any problems or have suggestions, welcome to [issues](https://github.com/slavamak/vite-plugin-shopify-import-maps/issues).

### Importing asset files (e.g. fonts, images) does not use the version parameter from Shopify CDN

This is not the scope of import map, as it is are designed to manage javascript modules. But you can load assets from Liquid files using the `asset_url` filter and consume them via CSS variables:

```liquid
{% #theme.liquid %}

{% style %}
  @font-face {
    font-family: 'Anton';
    src: url("{{ 'anton-v23-latin-regular.woff2' | asset_url }}") format('woff2');
    font-display: swap;
  }

  :root {
    --font-heading-family: 'Anton', sans-serif;
    --background-image: url('{{ 'background-image.svg' | asset_url }}');
  }
{% endstyle %}
```

```css
/* styles.css */

h1,
h2,
h3 {
  font-family: var(--font-heading-family);
}

body {
  background-image: var(--background-image);
}
```

## Acknowledges

- [vite-plugin-shopify](https://github.com/barrel/shopify-vite) - Shopify theme development using Vite

---
_Source: https://npm.io/package/vite-plugin-shopify-import-maps · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
