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

@huaiyou/config-build

v1.0.0

Published

Shared Vite build configuration

Readme

@huaiyou/config-build

基于 Vite 的共享构建配置,支持 TypeScript 和 React。

📦 安装

pnpm add -D @huaiyou/config-build vite

🚀 使用方法

Base 配置(通用项目)

创建 vite.config.ts

import { defineConfig, mergeConfig } from 'vite';
import { baseConfig } from '@huaiyou/config-build/base';

export default defineConfig(
  mergeConfig(baseConfig, {
    // 你的自定义配置
  })
);

React 配置

对于 React 项目:

import { defineConfig, mergeConfig } from 'vite';
import { reactConfig } from '@huaiyou/config-build/react';

export default defineConfig(
  mergeConfig(reactConfig, {
    // 你的自定义配置
    resolve: {
      alias: {
        '@': '/src',
      },
    },
  })
);

✨ 特性

Base 配置

  • ES2020 目标: 现代浏览器支持
  • 源码映射: 便于调试
  • 代码分割: 自动分离 vendor 代码
  • 资源优化: 压缩和优化静态资源
  • 开发服务器: 快速的 HMR 热更新

React 配置

继承 Base 配置,额外包含:

  • React 插件: 官方 React 插件
  • 自动 JSX: React 17+ 自动 JSX 运行时
  • Fast Refresh: 保持组件状态的热更新
  • 优化依赖: React 预构建优化

⚙️ 配置说明

构建选项

| 选项 | 值 | 说明 | | ----------------------- | --------- | ----------------------- | | target | es2020 | 构建目标 | | sourcemap | true | 生成源码映射 | | minify | esbuild | 使用 esbuild 压缩 | | chunkSizeWarningLimit | 1000 | chunk 大小警告限制 (KB) |

开发服务器

| 选项 | 值 | 说明 | | ------ | ------ | -------------- | | port | 3000 | 开发服务器端口 | | host | true | 监听所有地址 | | open | true | 自动打开浏览器 | | cors | true | 启用 CORS |

代码分割策略

自动将代码分割为以下 chunks:

  • vendor-react: React 和 React DOM
  • vendor: 其他第三方依赖
  • 业务代码按需动态导入

🔧 高级用法

路径别名

import { defineConfig, mergeConfig } from 'vite';
import { reactConfig } from '@huaiyou/config-build/react';
import path from 'path';

export default defineConfig(
  mergeConfig(reactConfig, {
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
        '@components': path.resolve(__dirname, 'src/components'),
        '@utils': path.resolve(__dirname, 'src/utils'),
      },
    },
  })
);

环境变量

import { defineConfig, mergeConfig } from 'vite';
import { reactConfig } from '@huaiyou/config-build/react';

export default defineConfig(
  mergeConfig(reactConfig, {
    define: {
      __APP_VERSION__: JSON.stringify(process.env.npm_package_version),
    },
  })
);

代理配置

import { defineConfig, mergeConfig } from 'vite';
import { reactConfig } from '@huaiyou/config-build/react';

export default defineConfig(
  mergeConfig(reactConfig, {
    server: {
      proxy: {
        '/api': {
          target: 'http://localhost:8080',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ''),
        },
      },
    },
  })
);

自定义插件

import { defineConfig, mergeConfig } from 'vite';
import { reactConfig } from '@huaiyou/config-build/react';
import { visualizer } from 'rollup-plugin-visualizer';

export default defineConfig(
  mergeConfig(reactConfig, {
    plugins: [
      visualizer({
        open: true,
        gzipSize: true,
        brotliSize: true,
      }),
    ],
  })
);

📝 Scripts 配置

package.json 中添加构建脚本:

{
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview",
    "type-check": "tsc --noEmit"
  }
}

🚀 性能优化建议

  1. 使用动态导入: 路由和大型组件使用 import()
  2. 优化图片: 使用现代格式 (WebP, AVIF)
  3. Tree Shaking: 按需导入第三方库
  4. 预加载: 关键资源使用 <link rel="preload">
  5. CDN: 静态资源部署到 CDN

🤝 贡献

欢迎提交 Issue 和 Pull Request 来改进配置。

📄 License

MIT