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

@xiao-ying/miniapp-vite

v1.0.0

Published

Reusable Vite config helpers for XiaoYing miniapps

Readme

@xiao-ying/miniapp-vite

给小应小程序项目复用的 Vite 配置工具集,当前主要提供两类能力:

  • createManualChunks:基于包名生成稳定、可读的 manualChunks 规则
  • createMiniAppManualChunkGroups:小应项目常用 chunk 分组预设
  • normalizeRouterBase:统一规范化 base / router base 字符串

该包刻意只按包名匹配,不对原始模块路径做 includes() 一类模糊判断,避免误伤诸如 react-photo-view 这样的包。

安装

在模板仓库或 SDK monorepo 内使用 workspace 依赖:

{
  "devDependencies": {
    "@xiao-ying/miniapp-vite": "workspace:*"
  }
}

在独立项目中使用本地路径依赖:

{
  "devDependencies": {
    "@xiao-ying/miniapp-vite": "file:../xiaoying-miniapp-sdk/vite"
  }
}

快速使用

import { defineConfig, loadEnv } from 'vite'
import {
  createManualChunks,
  createMiniAppManualChunkGroups,
  normalizeRouterBase,
} from '@xiao-ying/miniapp-vite'

const manualChunks = createManualChunks(createMiniAppManualChunkGroups())

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd())

  return {
    base: normalizeRouterBase(env.VITE_BASE_URL ?? env.VITE_ROUTER_BASE),
    build: {
      rollupOptions: {
        output: {
          manualChunks,
        },
      },
    },
  }
})

API

createManualChunks(groups)

创建一个可直接传给 build.rollupOptions.output.manualChunks 的函数。

type PackageMatcher =
  | string
  | { type: 'exact'; value: string }
  | { type: 'prefix'; value: string }
  | { type: 'scope'; value: string }
  | { type: 'regex'; value: RegExp }

type ManualChunkGroup = {
  chunkName: string
  matchers: readonly PackageMatcher[]
}

匹配行为基于 node_modules 中解析出的包名:

  • exact('react') 只命中 react
  • prefix('remark-') 可命中 remark-gfm
  • scope('@xiao-ying') 可命中 @xiao-ying/*
  • regex(/^micromark/) 可命中 micromark-*

createMiniAppManualChunkGroups(options?)

返回一组适合小应小程序项目的默认 chunk 分组预设,当前包括:

  • react-vendor
  • xy-runtime
  • xy-app
  • xy-cloud
  • data-vendor
  • zod-vendor
  • form-vendor

推荐用法:

const manualChunks = createManualChunks(createMiniAppManualChunkGroups())

如果项目只想在预设基础上做少量调整,可以传配置对象:

import { exact, prefix } from '@xiao-ying/miniapp-vite'

const manualChunks = createManualChunks(
  createMiniAppManualChunkGroups({
    exclude: ['data-vendor'],
    overrides: {
      'xy-app': {
        appendMatchers: [exact('@xiao-ying/miniapp-browser-bootstrap')],
      },
      'form-vendor': {
        chunkName: 'draft-vendor',
      },
    },
    extraGroups: [
      {
        chunkName: 'markdown-vendor',
        matchers: [exact('react-markdown'), prefix('remark-'), prefix('rehype-')],
      },
    ],
  })
)

支持的选项:

  • include:只保留指定的预设分组
  • exclude:排除指定的预设分组
  • overrides:按分组名覆盖默认配置
  • overrides.<group>.chunkName:重命名某个预设 chunk
  • overrides.<group>.matchers:完全替换某个预设分组的 matcher 列表
  • overrides.<group>.appendMatchers:在默认 matcher 后面追加 matcher
  • extraGroups:在预设分组后追加额外分组

getNodeModulePackageName(id)

从 Rollup/Vite 模块 id 中提取包名,兼容:

  • pnpm .pnpm/.../node_modules/... 结构
  • 普通 node_modules/...
  • workspace 包真实路径(如 monorepo 内的 sibling package)
  • Windows 路径
  • ?query / #hash 的 id

normalizeRouterBase(value)

将 base 规范化为:

  • 空值、/./ -> /
  • 其他值统一转成以 / 开头、以 / 结尾

Matcher Helpers

  • exact(value)
  • prefix(value)
  • scope(value)
  • regex(value)