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

@zero-bits/kernel

v3.4.0

Published

A framework-agnostic kernel for plugin loading and dependency injection.

Readme

@zero-bits/kernel

一个面向微前端架构的高性能、零防备、框架无关的内核引擎。

特性

  • 🏗 框架无关:核心层(Core)不依赖任何 UI 框架,支持 Vue/React/Svelte 等任意架构。
  • ⚛️ 原生 React 支持:提供专门的 React 绑定层,内置 PluginSlot 插槽组件和 Context 实例分发。
  • 🛡 极佳容错与并发
    • 自带多实例全局并发锁,同一个插件在多实例下只会加载一次网络请求。
    • 自动缓存失效处理(基于 URL)。
    • 内置超时控制(Timeout)与指数退避重试(Retry)。
  • 🔌 干净的 API 与自定义命名空间:支持隔离多个引擎在同一页面的内核变量,防止命名空间污染。

安装

npm install @zero-bits/kernel

导出说明

本包采用 exports 子路径导出设计,彻底隔离框架核心与视图层依赖:

  • @zero-bits/kernel (只包含纯核心逻辑,无 React 依赖)
  • @zero-bits/kernel/react (包含 React 插槽与上下文层,需在宿主安装 React)

快速使用 (React 环境)

1. 注册核心实例

在主应用入口或 Context 顶层,初始化并提供 Kernel 实例:

import React from 'react'
import { createKernel } from '@zero-bits/kernel'
import { KernelProvider } from '@zero-bits/kernel/react'

const kernel = createKernel({
  timeout: 5000,
  retryCount: 3,
  namespace: '__MY_APP__' // 隔离多内核实例冲突
})

// 注入共享依赖供子插件使用
kernel.regSharedModule('react', React)

export function App() {
  return (
    <KernelProvider kernel={kernel}>
      <MainLayout />
    </KernelProvider>
  )
}

2. 在业务组件中加载远端插件

直接使用 PluginSlot 占位,它会自动从上下文中获取 Kernel 并渲染远端组件。

import { PluginSlot } from '@zero-bits/kernel/react'
import { Spin } from 'antd'

export default function Dashboard() {
  return (
    <PluginSlot
      pluginName="user-dashboard"
      url="https://cdn.example.com/plugins/user-dashboard.js"
      styleUrls={["https://cdn.example.com/plugins/user-dashboard.css"]}
      fallback={<Spin spinning>Loading Plugin...</Spin>}
      renderError={(err, retry) => (
        <div style={{ color: 'red' }}>
          {err.message} <button onClick={retry}>重试</button>
        </div>
      )}
    />
  )
}

原生使用 (非 React)

对于 Vue 或原生 JS 开发者,可以直接使用核心加载器:

import { createKernel } from '@zero-bits/kernel'

const kernel = createKernel()
kernel.regSharedModule('vue', Vue)

kernel.loadPlugin('my-vue-plugin', {
  url: 'https://...',
  styleUrls: ['https://...']
}).then(mod => {
  // mod.default 即为插件导出的根组件/函数
  mod.default.mount('#app')
})

核心 API

createKernel(options?: KernelOptions)

创建并返回一个新的内核实例。

| 参数名 | 类型 | 默认值 | 说明 | | --- | --- | --- | --- | | timeout | number | 10000 | 加载超时时间(毫秒) | | retryCount | number | 2 | 网络失败自动重试次数 | | namespace | string | '__SMART_HUB__' | 全局拦截器的命名空间前缀 | | debug | boolean | true | 是否输出内核 warn/log |

KernelInstance

  • regSharedModule(name, instance, options): 注册主应用的共享依赖。
  • loadPlugin(pluginName, options): 请求加载远端插件。
  • unloadPlugin(pluginName): 卸载并在内存中清除某插件记录。
  • destroy(): 销毁整个内核实例并回收内存。