import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import tsconfigPaths from "vite-tsconfig-paths"; import { visualizer } from "rollup-plugin-visualizer"; import viteCompression from "vite-plugin-compression"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [ react(), tsconfigPaths(), visualizer({ open: true, //注意这里要设置为true,否则无效 gzipSize: true, brotliSize: true, }), viteCompression(), ], server: { proxy: { "/api": { rewrite: (path) => path.replace(/^\/api/, ""), target: "http://127.0.0.1:7001/api/v1", changeOrigin: true, }, }, }, build: { rollupOptions: { output: { manualChunks: { // key不重要,会被 chunkFileNames [hash].js重命名 "r-vendor": ["react"], "rd-vendor": ["react-dom"], "rdd-vendor": ["react-router-dom"], "dp-vendor": ["dplayer"], "cry-vendor": ["crypto-js"], "md-vendor": ["react-markdown"], }, // 入口文件名 entryFileNames: "assets/[hash].js", // 块文件名 chunkFileNames: "assets/[hash].js", // 资源文件名 css 图片等等 assetFileNames: "assets/[hash].[ext]", }, }, }, });