
Security News
PolinRider: North Korea-Linked Supply Chain Campaign Expands Across Open Source Ecosystems
PolinRider expands across npm, Packagist, Go modules, and Chrome extensions, using hidden loaders to target developer environments.
@huaiyou/config-build
Advanced tools
基于 Vite 的共享构建配置,支持 TypeScript 和 React。
pnpm add -D @huaiyou/config-build vite
创建 vite.config.ts:
import { defineConfig, mergeConfig } from 'vite';
import { baseConfig } from '@huaiyou/config-build/base';
export default defineConfig(
mergeConfig(baseConfig, {
// 你的自定义配置
})
);
对于 React 项目:
import { defineConfig, mergeConfig } from 'vite';
import { reactConfig } from '@huaiyou/config-build/react';
export default defineConfig(
mergeConfig(reactConfig, {
// 你的自定义配置
resolve: {
alias: {
'@': '/src',
},
},
})
);
继承 Base 配置,额外包含:
| 选项 | 值 | 说明 |
|---|---|---|
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 DOMvendor: 其他第三方依赖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,
}),
],
})
);
在 package.json 中添加构建脚本:
{
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"type-check": "tsc --noEmit"
}
}
import()<link rel="preload">欢迎提交 Issue 和 Pull Request 来改进配置。
MIT
FAQs
Shared Vite build configuration
We found that @huaiyou/config-build demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
PolinRider expands across npm, Packagist, Go modules, and Chrome extensions, using hidden loaders to target developer environments.

Security News
Open source attacks are accelerating as AI coding agents pull in dependencies faster, with less human review.

Research
/Security News
Malicious Chrome and Firefox extensions posed as free VPNs while stealing clipboard data through later extension updates.