npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vis-resm/importmap

v0.0.11

Published

runtime importmap management tool

Downloads

19

Readme

@vis-resm/importmap

resm 运行时 importmap 管理工具。

使用

一般使用

// package.json
{
  "name": "@examples/demo1",
  "version": "1.0.0",
  "dependencies": {
    "vue": "^2.6.14",
    "style-inject": "0.3.0"
  },
  "external": []
}
import { install } from "@vis-resm/importmap";
import pkg from "xxx/package.json";

install(pkg);

最后会自动在浏览器插入以下importmap

<script type="importmap-shim">
  {
    "imports": {
      "@examples/[email protected]/vue": "https://unpkg.com/[email protected]/dist/vue.esm.browser.min.js",
      "@examples/[email protected]/style-inject": "https://unpkg.com/[email protected]/dist/style-inject.es.js",
    }
  }
</script>

使用 external

有些情况下我们不想将dependencies的依赖全部生成 map,我们可以通过external字段指定。

// package.json
{
  "name": "@examples/demo1",
  "version": "1.0.0",
  "dependencies": {
    "vue": "^2.6.14",
    "style-inject": "0.3.0"
  },
  "external": ["vue"]
}
<script type="importmap-shim">
  {
    "imports": {
      "@examples/[email protected]/vue": "https://unpkg.com/[email protected]/dist/vue.esm.browser.min.js"
    }
  }
</script>

指定 url 库

目前支持unpkgnode_modules中获取。

import { install } from "@vis-resm/importmap";
import pkg from "xxx/package.json";

install(pkg, "unpkg");

install(pkg, "node_modules");

自定义源映射

import { install } from "@vis-resm/importmap";
import pkg from "xxx/package.json";

install(pkg, "custom", {
  "[email protected]": "./plugins/vue/browser.es.min.js",
});

容错处理

如果仓库中json文件中没有配置相关的 map 地址,有没有自定义提供 map 地址,会直接从https://unpkg.com/<name>@<version>?module地址获取相关的资源。

添加共用源

由于 npm 库模块众多,如果需要,请自行添加相关包映射在相关json配置中。

添加格式

  • 依赖名称:<name>@<version> : <url>
  • unpkg 匹配规则请查看官网:https://unpkg.com/
  • node_modules 匹配命名注意:<url> ---> node_modules/<name>-<version>/xxx/xxx

尽量精确到文件名,防止浏览器多次重定向影响包下载速度。

支持

本库是配合es-module-shims库使用的:https://github.com/guybedford/es-module-shims

由于目前 WICG 的 importmap 有部分功能还不完善,es-module-shims 过渡 importmap 比较方便:https://github.com/WICG/import-maps