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

@lhx-kit/vite-plugin

v1.1.0

Published

Vite plugin that translates project.config.ts into MPA build/dev configuration: chunk family grouping, CDN import rewriting, per-page output, local vendor fallback, and predefined gzip + brotli compression.

Readme

@lhx-kit/vite-plugin

⚡ Vite 插件,把 project.config.ts 翻译成生产级 MPA 构建管线。 per-page 输出、家族分组 chunk、CDN import 改写、本地 vendor fallback、gzip + brotli 预压缩——全部开箱即用。

npm license English


安装

pnpm add -D @lhx-kit/vite-plugin

peer 依赖:vite ^5 || ^6 || ^7。需要 Node.js >= 18.18.0

使用

import {defineConfig} from 'vite';
import {lhxKit} from '@lhx-kit/vite-plugin';

export default defineConfig({
  plugins: [lhxKit()]
});

就这一行。插件读取项目根目录的 project.config.ts,自动配置:

  • build.rollupOptions.input — 每个 pages.<name> 一个入口
  • resolve.alias — 来自 aliases 字段
  • define — 来自 envs.<mode>
  • manualChunks — 家族分组 vendor chunk
  • output.experimentalMinChunkSize — <10KB 的 chunk 自动合并

做了什么

🏗️ MPA 编排

project.config.ts
    ↓ (config 钩子)
.lhx-kit/pages/home.html  ← 每个 page 的中间 HTML
.lhx-kit/pages/about.html
    ↓ (rollup)
    ↓ (generateBundle 钩子)
dist/
├── home/index.html
├── home/assets/…
├── about/index.html
├── about/assets/…
└── shared/assets/…         ← 被 2+ 个 page 共用的 chunk

🎯 Chunk 策略

两层叠加:

// 第 1 层:家族分组
{
  react: ['react', 'react-dom', 'scheduler'],
  'react-router': ['react-router', 'react-router-dom', 'remix-run-router'],
  vue: ['vue', 'vue-demi'],
  'vue-state': ['pinia', 'vue-router']
}

// 第 2 层:<10KB 自动合并
output.experimentalMinChunkSize = 10 * 1024

效果:默认 React MPA 从 13 → 10 个 chunk,全部 > 1 KB。

完整推导见 性能优化

🌐 CDN 外挂(opt-in)

project.config.ts 声明:

cdn: {
  enabled: true,
  entries: [
    {
      name: 'vue',
      globalVar: 'Vue',
      urls: ['https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js']
    }
  ]
}

插件会:

  1. 改写 import {ref} from 'vue'const {ref} = window.Vue
  2. 注入 classic <script> loader 到每个 HTML(ES5 IIFE,无 bundler 依赖)
  3. Emit 本地 vendor fallback 到 shared/vendor/vue.js(CDN 全挂时加载)
  4. 支持 aliasGlobals / initScript,便于框架替换(例如 Preact 替代 React)

完整踩坑记录:CDN 外挂专题

🗜️ 预压缩(默认开启)

每个大于 1 KB 的 .js / .css / .html / .svg / .json 都会产出:

  • foo.js.gz — gzip level 9
  • foo.js.br — brotli quality 11(最高)

nginx 配置 gzip_static on; brotli_static on; 直接服务这些文件。

🧹 生产环境合理默认值

target: 'es2018'                 // 现代输出,压缩更小
assetsInlineLimit: 8 * 1024      // 小资源内联成 data URI
cssCodeSplit: true               // per-chunk CSS
esbuild.drop: ['debugger']
esbuild.pure: ['console.log', 'console.debug', 'console.trace']

用户的 vite.config.ts 仍可覆盖这些。


插件钩子

| 钩子 | enforce | 职责 | | --- | --- | --- | | config | pre | 把 project.config.ts 翻译成 UserConfig | | resolveId / load | – | @lhx-kit/virtual:config 虚拟模块 | | transform | – | 改写 bare imports(CDN 启用时) | | generateBundle | post | per-page 重组,注入 CDN loader | | (compress 副插件) | post | emit .gz / .br 文件 |

完整源码见 src/plugin.ts


选项

lhxKit({
  root?: string,              // 覆盖项目根目录
  mode?: string,              // 覆盖 env 模式
  pages?: string[],           // 显式 page 列表(通常通过 --page)
  intermediateDir?: string,   // 默认 '.lhx-kit/pages'
  outputLayout?: 'per-page' | 'flat',  // 默认 'per-page'
  sharedDir?: string,         // 默认 'shared'
  cleanUrls?: boolean,        // dev: /home → home.html,默认 true
  compress?: false | {threshold?, extensions?}  // 默认开启
})

依赖

| 依赖 | 用途 | | --- | --- | | @lhx-kit/config | 加载 project.config.ts | | @lhx-kit/runtime | CDN loader 源码生成器 | | vite(peer) | 宿主构建工具 |

仅 2 个内部依赖。无 lodash / glob / chokidar 膨胀。


文档

License

MIT © luhanxin


📦 安装

npm install @lhx-kit/vite-plugin
# 或
pnpm add @lhx-kit/vite-plugin

npm provenance

📖 文档与延伸阅读

🤝 参与贡献

欢迎 PR!请阅读 CONTRIBUTING.md,用户可见变更请用 pnpm changeset 声明。新手友好 label:good first issue / help wanted

📄 License

MIT © luhanxin

属于 @lhx-kit monorepo。每次发布都经过 npm Trusted Publishing(OIDC)签名——可在 npm 包页面验证 provenance 证明。