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

@zzzz-/vite-plugin-micro-lib

v0.0.6

Published

`vite-plugin-micro-lib` 是一个用于构建微型库的 Vite 插件。它可以帮助你将多个外部依赖打包成独立的模块,并生成相应的导入映射。

Readme

@zzzz-/vite-plugin-micro-lib

vite-plugin-micro-lib 是一个用于构建微型库的 Vite 插件。它可以帮助你将多个外部依赖打包成独立的模块,并生成相应的导入映射。

安装

使用 npm 安装:

npm install @zzzz-/vite-plugin-micro-lib --save-dev

使用 pnpm 安装:

pnpm add @zzzz-/vite-plugin-micro-lib --save-dev

使用

在你的 vite.config.ts 中配置该插件:

import { defineConfig } from 'vite';
import { microLib } from '@zzzz-/vite-plugin-micro-lib';

export default defineConfig({
    plugins: [
        microLib({
            outDir: './micro-lib',
            externalData: {
                react: {},
                'react/jsx-runtime': {},
                'react-dom': {},
                'react-dom/client': {},
                'react-router': { lib: true, },
                zustand: { lib: true, },
                // 添加更多外部依赖
            },
            // webAbsUrl: 'https://cdn.example.com/libs',
            // minify: true,
            // sourcemap: true,
            // customHandleGenerateCode: async (libItem, code) => {
            //     // 自定义代码处理逻辑
            //     return code;
            // },
        }),
    ],
});

配置选项

microLib 接受一个配置对象,包含以下选项:

  • outDir (string): 输出目录,默认为 ./micro-lib
  • externalData (Record<string, IExternalData>): 外部依赖数据,必须配置。
  • webAbsUrl (string): 外部依赖的绝对 URL 前缀,默认为空字符串。
  • minify (boolean): 是否压缩输出文件,默认为 true
  • sourcemap (boolean): 是否生成 sourcemap,默认为 true
  • customHandleGenerateCode (function): 自定义代码处理函数,接受 libItemcode 两个参数,返回处理后的代码。

类型定义

插件的类型定义如下:

interface IExternalData {
    /**
     * 是否启用 Tree Shaking
     * @default true
     */
    treeshake?: boolean;
    /**
     * 是否作为库进行打包
     * @default false
     */
    lib?: boolean;
}

interface ILibData extends IExternalData {
    name: string;
    version: string;
    scriptUrl: string;
    webAbsUrl: string;
    fileName: string;
}

interface IOptions {
    /**
     * 输出目录
     * @default './micro-lib'
     */
    outDir?: string;
    /**
     * 外部依赖数据
     */
    externalData: Record<string, IExternalData>;
    /**
     * 外部依赖的绝对 URL 前缀
     * @default ''
     */
    webAbsUrl?: string;
    /**
     * 是否压缩输出文件
     * @default true
     */
    minify?: boolean;
    /**
     * 是否生成 sourcemap
     * @default true
     */
    sourcemap?: boolean;
    /**
     * 自定义代码处理函数
     * @param libItem - 库项目信息
     * @param code - 生成的代码
     * @returns 处理后的代码或 Promise 对象
     */
    customHandleGenerateCode?: (libItem: IExternalData, code: string) => string | Promise<string>;
}