import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import { VitePWA } from 'vite-plugin-pwa' import { resolve } from 'path' // https://vitejs.dev/config/ export default defineConfig({ plugins: [ vue(), VitePWA({ registerType: 'autoUpdate', workbox: { cleanupOutdatedCaches: true, skipWaiting: true, clientsClaim: true } }) ], // 基础路径 base: '/schoolNewsWeb/', file: { downloadUrl: "http://school-news-serv:8081/schoolNewsServ/file/download/" }, // 输出目录 build: { outDir: 'dist', assetsDir: 'static', sourcemap: false, chunkSizeWarningLimit: 1500, rollupOptions: { output: { manualChunks: { 'vue-vendor': ['vue', 'vue-router', 'vuex'], 'element-plus': ['element-plus'] } } } }, // 路径别名 resolve: { alias: { '@': resolve(__dirname, 'src') }, extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'] }, // 环境变量 define: { 'process.env.BASE_URL': JSON.stringify('/schoolNewsWeb/'), 'process.env.VITE_API_BASE_URL': JSON.stringify('/api'), 'process.env.VITE_APP_TITLE': JSON.stringify('校园新闻管理系统') }, // 开发服务器配置(生产环境无效) server: { host: '0.0.0.0', port: 8080, open: '/schoolNewsWeb/', // 代理配置 proxy: { '/api': { target: 'http://school-news-serv:8081/schoolNewsServ', changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, '') } } }, // CSS 配置 css: { preprocessorOptions: { scss: { additionalData: '' } } } })