2025-06-09 10:23:45 +08:00
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
|
import path from 'path' // 引入 path 模块
|
|
|
|
|
|
2025-06-10 17:15:13 +08:00
|
|
|
import viteImagemin from 'vite-plugin-imagemin' // 新插件
|
2025-06-11 17:09:33 +08:00
|
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
|
|
|
import Components from 'unplugin-vue-components/vite'
|
2025-06-11 17:53:50 +08:00
|
|
|
|
|
|
|
|
import legacy from '@vitejs/plugin-legacy'
|
2025-06-09 10:23:45 +08:00
|
|
|
export default defineConfig({
|
2025-06-10 17:15:13 +08:00
|
|
|
plugins: [
|
|
|
|
|
vue(),
|
2025-06-11 17:53:50 +08:00
|
|
|
legacy({
|
|
|
|
|
targets: ['ie >= 11'],
|
|
|
|
|
additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
|
|
|
|
|
modernPolyfills: true // 启用现代浏览器的 polyfill
|
|
|
|
|
}),
|
2025-06-11 17:09:33 +08:00
|
|
|
AutoImport({
|
|
|
|
|
imports: ['vue', 'vue-router'] // 自动导入 Vue、Vue Router API
|
|
|
|
|
}),
|
|
|
|
|
Components({
|
|
|
|
|
dirs: ['src/components'] // 自动扫描组件目录
|
|
|
|
|
}),
|
2025-06-10 17:15:13 +08:00
|
|
|
viteImagemin({
|
|
|
|
|
// 基础压缩配置(可根据需求扩展)
|
|
|
|
|
gifsicle: { optimizationLevel: 7 },
|
|
|
|
|
optipng: { optimizationLevel: 7 },
|
|
|
|
|
mozjpeg: { quality: 80 },
|
|
|
|
|
pngquant: { quality: [0.8, 0.9] },
|
|
|
|
|
svgo: { plugins: [{ name: 'removeViewBox' }] }
|
|
|
|
|
})
|
|
|
|
|
],
|
2025-06-10 17:18:33 +08:00
|
|
|
build: {
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
output: {
|
|
|
|
|
manualChunks(id) {
|
|
|
|
|
if (id.includes('node_modules')) {
|
|
|
|
|
// 将第三方库单独分包(如 axios、vue 等)
|
|
|
|
|
return id.split('node_modules/')[1].split('/')[0]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-06-09 10:23:45 +08:00
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
'@': path.resolve(__dirname, 'src') // 添加路径别名
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|