Files
cutThink_lite/vite.config.js

101 lines
2.4 KiB
JavaScript
Raw Normal View History

import { defineConfig } from 'vite'
// Vite 配置文件 - 优化生产环境构建
export default defineConfig(({ mode }) => {
const isProduction = mode === 'production'
return {
// 开发服务器配置
server: {
port: 5173,
strictPort: true,
watch: {
// 监听文件变化
ignored: ['**/src-tauri/**'],
},
},
// 构建配置
build: {
// Tauri 使用 Chrome WebView可以设置更高的 target
target: 'es2020',
// 输出目录
outDir: './dist',
// 生产环境不生成 source map减小体积
sourcemap: !isProduction,
// 代码分割配置
rollupOptions: {
output: {
// 手动代码分割
manualChunks: {
// 将 Tauri API 单独分割
'tauri-api': ['@tauri-apps/api'],
},
// 资源文件命名
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: (assetInfo) => {
const name = assetInfo.name || ''
if (name.endsWith('.css')) {
return 'assets/css/[name]-[hash][extname]'
}
if (/\.(png|jpe?g|gif|svg|webp|ico)$/.test(name)) {
return 'assets/images/[name]-[hash][extname]'
}
return 'assets/[name]-[hash][extname]'
},
},
},
// 压缩配置
minify: 'terser',
terserOptions: {
compress: {
// 删除 console
drop_console: isProduction,
// 删除 debugger
drop_debugger: isProduction,
// 移除无用代码
pure_funcs: isProduction ? ['console.log', 'console.info'] : [],
},
format: {
// 移除注释
comments: false,
},
},
// 设置 chunk 大小警告阈值KB
chunkSizeWarningLimit: 500,
// CSS 代码分割
cssCodeSplit: true,
// CSS 压缩
cssMinify: true,
},
// 依赖优化
optimizeDeps: {
include: ['@tauri-apps/api'],
},
// 路径配置 - 相对路径以支持 Tauri
base: './',
// 开发时不清屏,方便看到错误信息
clearScreen: false,
// 生产环境优化
...(isProduction && {
// 关闭一些开发时的功能
esbuild: {
// 移除 console.log
drop: isProduction ? ['console', 'debugger'] : [],
},
}),
}
})