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

vite-node-addon-loader

v1.0.0

Published

A Vite plugin for loading and bundling Node.js native addon (.node) files

Readme

Vite Node Addon Loader

一个Vite插件,用于处理和打包Node.js原生扩展(.node)文件。

功能特性

  • ✅ 自动识别和处理 .node 文件
  • ✅ 为每个.node文件生成带hash的文件名
  • ✅ 自动生成使用 createRequire 的加载代码
  • ✅ 将.node文件复制到构建输出目录
  • ✅ 支持自定义配置

安装

npm install --save-dev vite-node-addon-loader

使用方法

1. 在vite.config.js中配置插件

import { defineConfig } from 'vite';
import nodeAddonLoader from 'vite-node-addon-loader';

export default defineConfig({
  plugins: [
    nodeAddonLoader({
      include: /\.node$/,      // 匹配.node文件的正则表达式
      hashLength: 8           // hash长度
    })
  ]
});

2. 在代码中导入.node文件

// 直接导入.node文件
import myAddon from './path/to/your/addon.node';

// 使用导入的addon
console.log(myAddon);

3. 构建项目

npm run build

构建后,插件会:

  • your/addon.node 复制到 dist/your/addon.[hash].node
  • 自动生成使用 createRequire 加载的代码

配置选项

| 选项 | 类型 | 默认值 | 描述 | |------|------|--------|------| | include | RegExp | /\.node$/ | 匹配.node文件的正则表达式 | | outputDir | string | 'dist' | 输出目录 | | hashLength | number | 8 | 生成的hash长度 |

示例

项目目录结构:

project/
├── src/
│   └── index.js
├── native/
│   └── addon.node
├── vite.config.js
└── package.json

src/index.js:

import addon from '../native/addon.node';

console.log('Addon loaded:', addon);

构建后:

dist/
├── index.js
├── native/
│   └── addon.a1b2c3d4.node  // 带hash的文件名
└── ...

注意事项

  • 确保.node文件存在且可访问
  • 插件会在构建时复制.node文件,开发模式下不会复制
  • 生成的hash基于文件内容,确保文件内容变化时hash也会变化