68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
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: './' // 相对路径(推荐),或绝对路径 '/'
|
||
})
|