2025-06-09 10:23:45 +08:00
|
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
2025-07-11 14:51:12 +08:00
|
|
|
|
import path from 'path'
|
2025-06-09 10:23:45 +08:00
|
|
|
|
|
2025-07-11 14:51:12 +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-12 19:01:03 +08:00
|
|
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
2025-07-11 14:51:12 +08:00
|
|
|
|
import { visualizer } from 'rollup-plugin-visualizer'
|
2025-06-11 17:53:50 +08:00
|
|
|
|
import legacy from '@vitejs/plugin-legacy'
|
2025-06-19 19:00:33 +08:00
|
|
|
|
|
2025-07-11 14:51:12 +08:00
|
|
|
|
export default defineConfig(({ mode }) => ({
|
|
|
|
|
|
// 新增:指定打包基础路径为 /web/
|
|
|
|
|
|
// base: '/web/', // 所有资源引用会以 /web/ 为前缀(如静态资源路径变为 /web/static/js/xxx.js)
|
|
|
|
|
|
base: mode === 'production' ? '/web/' : '/',
|
|
|
|
|
|
|
2025-06-10 17:15:13 +08:00
|
|
|
|
plugins: [
|
2025-07-11 14:51:12 +08:00
|
|
|
|
visualizer({
|
|
|
|
|
|
filename: './node_modules/.cache/visualizer/stats.html',
|
|
|
|
|
|
open: true,
|
|
|
|
|
|
gzipSize: true,
|
|
|
|
|
|
brotliSize: true
|
|
|
|
|
|
}),
|
2025-06-10 17:15:13 +08:00
|
|
|
|
vue(),
|
2025-06-20 18:44:15 +08:00
|
|
|
|
...(process.env.NODE_ENV === 'production'
|
|
|
|
|
|
? [
|
|
|
|
|
|
legacy({
|
|
|
|
|
|
targets: ['ie >= 11'],
|
|
|
|
|
|
additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
|
|
|
|
|
|
modernPolyfills: true
|
|
|
|
|
|
})
|
|
|
|
|
|
]
|
|
|
|
|
|
: []),
|
2025-06-11 17:09:33 +08:00
|
|
|
|
AutoImport({
|
2025-07-11 14:51:12 +08:00
|
|
|
|
imports: ['vue', 'vue-router'],
|
2025-06-12 19:01:03 +08:00
|
|
|
|
resolvers: [
|
|
|
|
|
|
ElementPlusResolver({
|
2025-07-11 14:51:12 +08:00
|
|
|
|
importStyle: false,
|
|
|
|
|
|
directives: true
|
2025-06-12 19:01:03 +08:00
|
|
|
|
})
|
2025-07-04 11:29:23 +08:00
|
|
|
|
],
|
2025-07-11 14:51:12 +08:00
|
|
|
|
dts: true
|
2025-06-11 17:09:33 +08:00
|
|
|
|
}),
|
|
|
|
|
|
Components({
|
2025-06-12 19:01:03 +08:00
|
|
|
|
resolvers: [
|
|
|
|
|
|
ElementPlusResolver({
|
2025-07-11 14:51:12 +08:00
|
|
|
|
importStyle: false
|
2025-06-12 19:01:03 +08:00
|
|
|
|
})
|
2025-07-11 14:51:12 +08:00
|
|
|
|
],
|
|
|
|
|
|
dts: true,
|
|
|
|
|
|
include: [/\.vue$/, /\.vue\?vue/, /\.tsx$/],
|
|
|
|
|
|
dirs: ['src/components']
|
2025-06-11 17:09:33 +08:00
|
|
|
|
}),
|
2025-06-20 18:44:15 +08:00
|
|
|
|
...(process.env.NODE_ENV !== 'development'
|
|
|
|
|
|
? [
|
|
|
|
|
|
viteImagemin({
|
|
|
|
|
|
gifsicle: { optimizationLevel: 7 },
|
|
|
|
|
|
optipng: { optimizationLevel: 7 },
|
|
|
|
|
|
mozjpeg: { quality: 80 },
|
|
|
|
|
|
pngquant: { quality: [0.8, 0.9] },
|
|
|
|
|
|
svgo: { plugins: [{ name: 'removeViewBox' }] }
|
|
|
|
|
|
})
|
|
|
|
|
|
]
|
|
|
|
|
|
: [])
|
2025-06-10 17:15:13 +08:00
|
|
|
|
],
|
2025-06-19 19:00:33 +08:00
|
|
|
|
server: {
|
|
|
|
|
|
host: '0.0.0.0', // 允许外部访问
|
|
|
|
|
|
port: 3000, // 指定端口
|
|
|
|
|
|
open: true, // 自动打开浏览器
|
|
|
|
|
|
fs: {
|
|
|
|
|
|
strict: false // 允许访问项目根目录外的文件
|
|
|
|
|
|
},
|
|
|
|
|
|
// 代理配置(如有跨域问题)
|
|
|
|
|
|
proxy: {
|
|
|
|
|
|
'/api': {
|
|
|
|
|
|
target: 'http://localhost:8080',
|
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
|
rewrite: path => path.replace(/^\/api/, '')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-07-11 14:51:12 +08:00
|
|
|
|
// proxy: {
|
|
|
|
|
|
// '^/dev-api': {
|
|
|
|
|
|
// target: ''
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2025-06-19 19:00:33 +08:00
|
|
|
|
},
|
|
|
|
|
|
optimizeDeps: {
|
2025-07-11 14:51:12 +08:00
|
|
|
|
// include: ['element-plus']
|
2025-06-19 19:00:33 +08:00
|
|
|
|
},
|
2025-06-10 17:18:33 +08:00
|
|
|
|
build: {
|
2025-07-11 14:51:12 +08:00
|
|
|
|
chunkSizeWarningLimit: 1000,
|
2025-06-10 17:18:33 +08:00
|
|
|
|
rollupOptions: {
|
|
|
|
|
|
output: {
|
2025-07-04 11:29:23 +08:00
|
|
|
|
manualChunks(id) {
|
|
|
|
|
|
if (id.includes('node_modules')) {
|
|
|
|
|
|
// 将第三方库单独分包(如 axios、vue 等)
|
|
|
|
|
|
return id.split('node_modules/')[1].split('/')[0]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-07-11 14:51:12 +08:00
|
|
|
|
// chunkFileNames: 'static/js/[name]-[hash].js',
|
|
|
|
|
|
// entryFileNames: 'static/js/[name]-[hash].js',
|
|
|
|
|
|
// assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
|
2025-06-10 17:18:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2025-06-12 19:01:03 +08:00
|
|
|
|
css: {
|
|
|
|
|
|
preprocessorOptions: {
|
2025-06-16 18:34:43 +08:00
|
|
|
|
scss: {
|
|
|
|
|
|
api: 'modern-compiler'
|
|
|
|
|
|
},
|
2025-06-12 19:01:03 +08:00
|
|
|
|
less: {
|
|
|
|
|
|
additionalData: `@import "@/styles/global.less";`,
|
|
|
|
|
|
javascriptEnabled: true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2025-06-09 10:23:45 +08:00
|
|
|
|
resolve: {
|
|
|
|
|
|
alias: {
|
2025-07-11 14:51:12 +08:00
|
|
|
|
'@': path.resolve(__dirname, 'src')
|
2025-06-09 10:23:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-07-11 14:51:12 +08:00
|
|
|
|
}))
|