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

@dev-to/react-plugin

v1.2.0

Published

一个用于 **Vite + React** 的“宿主桥接”插件:在 Vite Dev Server 上暴露稳定的桥接入口(contract/init/runtime/debug),让非 Vite 页面(例如 Electron、旧系统、微前端容器)也能加载并热更新 Vite 侧的 React 组件。

Readme

@dev-to/react-plugin

一个用于 Vite + React 的“宿主桥接”插件:在 Vite Dev Server 上暴露稳定的桥接入口(contract/init/runtime/debug),让非 Vite 页面(例如 Electron、旧系统、微前端容器)也能加载并热更新 Vite 侧的 React 组件。

安装

pnpm add -D @dev-to/react-plugin

使用

vite.config.ts 中启用:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { devToReactPlugin } from '@dev-to/react-plugin'

export default defineConfig({
  plugins: [
    react(),
    devToReactPlugin({
      // 组件名 -> 入口路径(相对/绝对路径均可)
      MyCard: 'src/MyCard.tsx',

      // '/' 表示使用默认入口(优先 src/App.*,其次 src/index.*)
      Other: '/'
    })
  ]
})

components 参数形态

  • devToReactPlugin():通配符模式(默认 '*': '/'),便于开发;但 dev-to build(等价于 vite build --mode lib)需要显式 componentName。
  • devToReactPlugin('MyCard'):字符串快捷模式,等价于 { MyCard: '/' }
  • devToReactPlugin({ MyCard: 'src/MyCard.tsx' }):显式映射(推荐,且 lib 构建必须)。

稳定桥接路径

插件会提供以下稳定路径(v2.0+ 统一命名空间):

框架无关端点(Framework-Agnostic)

  • Discovery (新): /__dev_to__/discovery.json - 统一发现端点,包含框架信息、服务器元数据、所有可用端点
  • Debug HTML: /__dev_to__/debug.html - 可视化调试面板
  • Debug JSON: /__dev_to__/debug.json - JSON 格式的调试信息

React 专用端点(React-Specific)

  • Contract (兼容): /__dev_to__/react/contract.js - 桥接合约
  • Init: /__dev_to__/react/init.js - 安装 HMR + React Refresh preamble
  • Runtime: /__dev_to__/react/runtime.js - React + ReactDOMClient
  • Loader UMD: /__dev_to__/react/loader.js - ReactLoader UMD 构建
  • Component Loaders: /__dev_to__/react/loader/{ComponentName}.js - 单组件加载器

这些路径与事件名常量集中在 @dev-to/shared,用于保证 Vite 侧与宿主侧协议一致。

HMR 事件

  • Full Reload: dev_to:react:full-reload
  • HMR Update: dev_to:react:hmr-update

生产构建(Library Mode)

执行 dev-to build(等价于 vite build --mode lib)时,插件会按 components 参数为每个组件产出一个 UMD bundle,默认输出到 dist/<component>/。 支持透传 Vite build 参数,例如:dev-to build --sourcemap --outDir dist-lib

提示:'*': '/' 的通配符模式仅适合开发;lib 构建请显式列出组件名。

与 @dev-to/react-loader 配套

宿主侧建议使用 @dev-to/react-loaderReactLoader,它会自动:

  • 拉取 contract
  • 先加载 init(确保 Fast Refresh 生效)
  • 再加载 React Runtime 与目标模块
  • 监听 full-reload 事件并触发热重载