(rebase) avoid dist and binary
This commit is contained in:
62
vite.config.ts
Normal file
62
vite.config.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
server: {
|
||||
host: '0.0.0.0', // 允许外部访问
|
||||
port: 5173,
|
||||
open: false, // 服务器环境不自动打开浏览器
|
||||
cors: true, // 启用CORS
|
||||
},
|
||||
preview: {
|
||||
host: '0.0.0.0',
|
||||
port: 5173,
|
||||
},
|
||||
build: {
|
||||
// 🔧 优化构建配置,解决大块警告
|
||||
chunkSizeWarningLimit: 1000, // 提高块大小警告限制到1MB
|
||||
rollupOptions: {
|
||||
output: {
|
||||
// 📦 手动代码分割,优化加载性能
|
||||
manualChunks: {
|
||||
// React相关库单独打包
|
||||
'react-vendor': ['react', 'react-dom'],
|
||||
// Redux相关库单独打包
|
||||
'redux-vendor': ['@reduxjs/toolkit', 'react-redux'],
|
||||
// UI库单独打包
|
||||
'ui-vendor': ['antd'],
|
||||
// Socket.IO单独打包
|
||||
'socket-vendor': ['socket.io-client'],
|
||||
},
|
||||
// 📁 优化文件命名
|
||||
chunkFileNames: 'assets/js/[name]-[hash].js',
|
||||
entryFileNames: 'assets/js/[name]-[hash].js',
|
||||
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
|
||||
}
|
||||
},
|
||||
// 🚀 构建优化
|
||||
sourcemap: false, // 生产环境不生成sourcemap
|
||||
minify: 'terser', // 使用terser压缩
|
||||
terserOptions: {
|
||||
compress: {
|
||||
drop_console: true, // 移除console
|
||||
drop_debugger: true, // 移除debugger
|
||||
},
|
||||
},
|
||||
// 📊 资源优化
|
||||
assetsInlineLimit: 4096, // 小于4KB的资源内联为base64
|
||||
},
|
||||
// 🔧 依赖优化
|
||||
optimizeDeps: {
|
||||
include: [
|
||||
'react',
|
||||
'react-dom',
|
||||
'@reduxjs/toolkit',
|
||||
'react-redux',
|
||||
'antd',
|
||||
'socket.io-client'
|
||||
],
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user