Files
cpzs-frontend-new/vite.config.js
2026-01-15 18:16:50 +08:00

52 lines
1.3 KiB
JavaScript
Raw Permalink 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 { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vite.dev/config/
export default defineConfig({
plugins: [
vue(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
server: {
host: '0.0.0.0', // 允许局域网访问
port: 5173
},
build: {
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
},
// 生成带hash的文件名避免浏览器缓存
rollupOptions: {
output: {
// 入口文件名
entryFileNames: 'assets/js/[name].[hash].js',
// 代码分割文件名
chunkFileNames: 'assets/js/[name].[hash].js',
// 资源文件名
assetFileNames: (assetInfo) => {
// 根据文件类型分目录存放
if (assetInfo.name.endsWith('.css')) {
return 'assets/css/[name].[hash].[ext]'
}
if (/\.(png|jpe?g|gif|svg|webp|ico)$/.test(assetInfo.name)) {
return 'assets/images/[name].[hash].[ext]'
}
if (/\.(woff2?|eot|ttf|otf)$/.test(assetInfo.name)) {
return 'assets/fonts/[name].[hash].[ext]'
}
return 'assets/[name].[hash].[ext]'
}
}
}
}
})