Files
chenhaodong 3116d3bf8b 优化打包
2026-06-23 20:08:35 +08:00

70 lines
1.7 KiB
JavaScript

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const resolve = (dir) => path.resolve(__dirname, dir)
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd())
return {
plugins: [
vue(),
createSvgIconsPlugin({
iconDirs: [resolve('src/icons/svg')],
symbolId: 'icon-[name]'
})
],
resolve: {
alias: {
'@': resolve('src')
}
},
define: {
'process.env': {}
},
server: {
port: 9527,
open: true
},
build: {
outDir: '../exam-api/src/main/resources/static',
emptyOutDir: true,
assetsDir: 'static',
sourcemap: false,
chunkSizeWarningLimit: 1000,
rollupOptions: {
onwarn(warning, warn) {
// 忽略第三方库中的 /*#__PURE__*/ 注释警告
if (warning.code === 'INVALID_ANNOTATION') return
warn(warning)
},
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
manualChunks(id) {
if (id.includes('node_modules')) {
if (id.includes('element-plus')) {
return 'chunk-elementPlus'
}
return 'chunk-libs'
}
}
}
}
},
css: {
preprocessorOptions: {
scss: {
api: 'modern',
silenceDeprecations: ['import']
}
}
}
}
})