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 🙏

© 2026 – Pkg Stats / Ryan Hefner

hb-third-lib

v0.0.80

Published

海豹常用第三方库,使用模块联邦实现

Downloads

158

Readme

hb-third-lib

海豹常用第三方库,使用模块联邦实现

使用远程库

yarn add hel-micro hb-third-lib

懒加载远程模块

import helMicro from "hel-micro";

export async function bootstrap() {
  const lib = await helMicro.preFetchLib("hb-third-lib", {
    enableDiskCache: true,
    skip404Sniff: true,
    apiPrefix: "https://cdn.jsdelivr.net/npm",
    hook: {
      beforeAppendAssetNode(passCtx) {
        const { url, setAssetUrl } = passCtx;
        const jsdelivrUrl = url.replace(
          "https://unpkg.com",
          "https://cdn.jsdelivr.net/npm"
        );
        setAssetUrl(jsdelivrUrl);
      },
    },
  });
  return;
}
bootstrap().catch(() => false);

预加载远程模块

src/loadApp.ts

import { createApp } from "vue";
import App from "./App.vue";

const fn = async () => {
  const app = createApp(App);
  app.mount("#app");
};

fn().catch(() => false);

src/main.ts

import * as Vue from "vue";
import { bindVueRuntime, preFetchLib } from "hel-micro";
bindVueRuntime({ Vue });

async function bootstrap() {
  await preFetchLib("hb-third-lib", {
    skip404Sniff: true,
    // TODO: 可以替换cdn源
    skip404Sniff: true,
    apiPrefix: "https://cdn.jsdelivr.net/npm",
    hook: {
      beforeAppendAssetNode(passCtx) {
        const { url, setAssetUrl } = passCtx;
        const jsdelivrUrl = url.replace(
          "https://unpkg.com",
          "https://cdn.jsdelivr.net/npm"
        );
        setAssetUrl(jsdelivrUrl);
      },
    },
  }).catch(() => false);
  await import("./loadApp").catch(() => false);
}
void bootstrap().catch(() => false);

使用

import { isArray } from "hb-third-lib";

function callRemoteMethod() {
  return isArray([]);
}

本地联调

进入 hb-third-lib 项目

yarn start //启动项目

然后在宿主项目里

async function bootstrap() {
  await preFetchLib("hb-third-lib", {
    custom: {
      host: "http://localhost:7001",
    },
    skip404Sniff: true,
    // apiPrefix: "https://cdn.jsdelivr.net/npm",
  }).catch(() => false);
  await import("./loadApp").catch(() => false);
}
void bootstrap().catch(() => false);

就可以愉快的本地联调啦

原理

你在宿主项目使用时,实践上只是使用了「hb-third-lib」导出的 lib 代理对象

// proxy 代理对象
export const lib = exposeLib < LibProperties > LIB_NAME;

// 这里是我们为了方便使用而结构导出的
export const { hbUtils } = lib;

// 这里是我们为了方便使用而结构导出的
export const { isArray } = hbUtils;

而实际逻辑都是在客户端预加载的时候,才被加载进来,它们被存放在hb-third-lib这个位置。

假设说,isArray 的逻辑有变,在「hb-third-lib」发布后,宿主项目不需要任何变动直接就能使用。

但如果 hbUtils 下新增了 isString 方法。

// 这种使用方式,你就需要将「hb-third-lib」升级到最新版本
import { isArray, isString } from "hb-third-lib";

function callRemoteMethod() {
  return isArray([]) && isString("");
}
// 这种使用方式,继续无视一切,直接使用就好了
import { hbUtils } from "hb-third-lib";

function callRemoteMethod() {
  return hbUtils.isArray([]) && hbUtils.isString("");
}