ubermanu/magento2-es-import-map

ES 模块自动生成的导入映射

安装: 7

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 3

分支: 0

开放问题: 0

语言:JavaScript

类型:magento2-module

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

This package is auto-updated.

Last update: 2024-09-23 20:22:23 UTC


README

此模块生成一个用于与 JS 模块一起使用的导入映射脚本标签。
通过 https://github.com/guybedford/es-module-shims 提供跨浏览器支持。

安装

composer require ubermanu/magento2-es-import-map

示例

在您的模块 view/frontend/web/mjs 文件夹中创建一个 example.mjs 文件

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

将以下内容添加到任何 *.phtml 模板文件中

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

命名导入

要使用命名导入,在您的模块(或主题)的视图目录中创建一个 import-map.json 文件

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