ubermanu/magento2-es-import-map

Auto generated import-map for ES modules

Installs: 7

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Language:JavaScript

Type:magento2-module

v3.0.0 2022-10-14 17:11 UTC

This package is auto-updated.

Last update: 2024-05-23 19:40:00 UTC


README

This module generates an import-map script tag to be used with JS modules.
Cross browser support is provided by https://github.com/guybedford/es-module-shims.

Install

composer require ubermanu/magento2-es-import-map

Example

Create a example.mjs file into your module view/frontend/web/mjs folder:

// app/code/Vendor/Module/view/frontend/web/mjs/example.mjs
export const something = 'Hello world';

Add the following to any *.phtml template file:

<script type="module">
  import { something } from '/Vendor_Module/mjs/example.mjs';
  alert(something);
</script>

Named imports

To use named imports, create an import-map.json file into the view dir of your module (or theme):

// app/code/Vendor/Module/view/frontend/import-map.json
{
    "imports": {
        "jquery": "https://cdn.skypack.dev/jquery"
    }
}