JGJS2026/vite.config.ts
2026-03-07 11:47:07 +08:00

68 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import path from 'node:path'
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue(), tailwindcss()],
// 路径别名(和 tsconfig 保持一致)
resolve: {
alias: {
'@': path.resolve(__dirname, 'src')
}
},
// 核心build 输出配置
build: {
// 1. 打包输出根目录(默认 dist可自定义
outDir: 'dist',
// 2. 静态资源js/css/img输出子目录默认 assets
assetsDir: 'static',
// 3. 生成的静态资源文件名是否包含哈希(用于缓存控制)
assetsInlineLimit: 4096, // 小于4kb的资源内联不生成文件
rolldownOptions: {
checks: {
pluginTimings: false
},
// 4. 自定义入口/出口(进阶,一般无需修改)
output: {
// 自定义 chunk 文件名(拆分公共代码)
chunkFileNames: 'static/js/[name]-[hash].js',
// 自定义入口文件名
entryFileNames: 'static/js/[name]-[hash].js',
// 自定义 css 文件名
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
codeSplitting: {
minSize: 20 * 1024,
groups: [
{
name: 'vendor-ag-grid',
test: /node_modules[\\/](ag-grid-community|ag-grid-enterprise|ag-grid-vue3|@ag-grid-community)[\\/]/,
priority: 30,
entriesAware: true,
maxSize: 450 * 1024
},
{
name: 'vendor-vue',
test: /node_modules[\\/](vue|pinia|@vue|pinia-plugin-persistedstate)[\\/]/,
priority: 20
},
{
name: 'vendor-ui',
test: /node_modules[\\/](reka-ui|@floating-ui|lucide-vue-next|@iconify[\\/]vue)[\\/]/,
priority: 10
}
]
}
}
},
chunkSizeWarningLimit: 1800,
// 5. 生产环境是否生成 sourcemap默认 false关闭可减小包体积
sourcemap: false,
// 6. 清空输出目录(默认 true
emptyOutDir: true
},
// 7. 部署的公共路径(关键!如部署到子路径 https://xxx.com/my-app/,需设为 '/my-app/'
base: './' // 相对路径(推荐),或绝对路径 '/'
})