|
|
@@ -1,7 +1,7 @@
|
|
|
import { defineConfig, loadEnv } from "vite"
|
|
|
import { resolve } from "path"
|
|
|
import createVitePlugins from "./vite/plugins"
|
|
|
-
|
|
|
+//import { visualizer } from "rollup-plugin-visualizer"
|
|
|
// https://vitejs.dev/config/
|
|
|
export default defineConfig(({ mode, command }) => {
|
|
|
const env = loadEnv(mode, process.cwd())
|
|
|
@@ -11,7 +11,84 @@ export default defineConfig(({ mode, command }) => {
|
|
|
// 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
|
|
|
// 例如 https://www.vber.net/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.vber.net/admin/,则设置 baseUrl 为 /admin/。
|
|
|
base: VITE_APP_ENV === "production" ? "/" : "/",
|
|
|
- plugins: createVitePlugins(env, command === "build"),
|
|
|
+ plugins: [
|
|
|
+ ...createVitePlugins(env, command === "build")
|
|
|
+ //,visualizer()
|
|
|
+ ],
|
|
|
+ build: {
|
|
|
+ minify: "terser", // 启用 terser 压缩
|
|
|
+ terserOptions: {
|
|
|
+ compress: {
|
|
|
+ pure_funcs: ["console.log"], // 只删除 console.log
|
|
|
+ //drop_console: true, // 删除所有 console
|
|
|
+ drop_debugger: true // 删除 debugger
|
|
|
+ }
|
|
|
+ },
|
|
|
+ rollupOptions: {
|
|
|
+ output: {
|
|
|
+ // 最小化拆分包
|
|
|
+ manualChunks(id) {
|
|
|
+ if (id.includes("node_modules")) {
|
|
|
+ if (id.includes("node_modules/element-plus")) {
|
|
|
+ return "vb_plugin_element-plus"
|
|
|
+ }
|
|
|
+ if (id.includes("node_modules/nprogress")) {
|
|
|
+ return "vb_plugin_nprogress" //单独打包
|
|
|
+ }
|
|
|
+ if (id.includes("node_modules/quill")) {
|
|
|
+ return "vb_plugin_quill"
|
|
|
+ }
|
|
|
+ if (id.includes("node_modules/echarts")) {
|
|
|
+ return "vb_plugin_echarts"
|
|
|
+ }
|
|
|
+ if (id.includes("node_modules/lodash")) {
|
|
|
+ return "vb_plugin_lodash"
|
|
|
+ }
|
|
|
+ // 通过拆分包的方式将所有来自node_modules的模块打包到单独的chunk中
|
|
|
+ return "vb_plugin_vendor"
|
|
|
+ }
|
|
|
+ // 将pinia的全局库单独打包,避免和页面一起打包造成资源重复引入
|
|
|
+ if (id.includes(resolve(__dirname, "/src/stores/index.ts"))) {
|
|
|
+ return "vb_store"
|
|
|
+ }
|
|
|
+ if (id.includes("/src/components/") && id.includes("/Vb")) {
|
|
|
+ return "vb_components"
|
|
|
+ }
|
|
|
+ if (id.includes("/src/core/utils/") && id.includes("/Vb")) {
|
|
|
+ return "vb_utils"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 设置chunk的文件名格式
|
|
|
+ chunkFileNames: (chunkInfo) => {
|
|
|
+ if (chunkInfo.isEntry) {
|
|
|
+ return "index.[hash].js"
|
|
|
+ }
|
|
|
+ if (chunkInfo.name === "index") {
|
|
|
+ const facadeModuleId = chunkInfo.facadeModuleId
|
|
|
+ ? chunkInfo.facadeModuleId.split("/")
|
|
|
+ : []
|
|
|
+ const fileName = facadeModuleId[facadeModuleId.length - 2] || "[name]"
|
|
|
+ // 根据chunk的facadeModuleId(入口模块的相对路径)生成chunk的文件名
|
|
|
+ return `js/vb_view_${fileName}.[hash].js`
|
|
|
+ }
|
|
|
+ return `js/[name].[hash].js`
|
|
|
+ },
|
|
|
+ // 设置入口文件的文件名格式
|
|
|
+ entryFileNames: "js/[name].[hash].js",
|
|
|
+ // 设置静态资源文件的文件名格式
|
|
|
+ assetFileNames(assetInfo) {
|
|
|
+ if (assetInfo.name?.endsWith(".css")) {
|
|
|
+ return "css/[name].[hash].[ext]"
|
|
|
+ }
|
|
|
+ const imgArray = [".png", "jpg", ".jpeg", "webp ", ".svg", ".gif"]
|
|
|
+ if (imgArray.some((v) => assetInfo.name?.endsWith(v))) {
|
|
|
+ return "img/[name].[hash].[ext]"
|
|
|
+ }
|
|
|
+ return "media/asset/[name].[hash:4].[ext]"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
resolve: {
|
|
|
// https://cn.vitejs.dev/config/#resolve-alias
|
|
|
alias: {
|
|
|
@@ -60,6 +137,7 @@ export default defineConfig(({ mode, command }) => {
|
|
|
// 设为 true 时若端口已被占用则会直接退出,而不是尝试下一个可用端口
|
|
|
strictPort: true,
|
|
|
open: true,
|
|
|
+ cors: false,
|
|
|
proxy: {
|
|
|
// "/prod-api": {
|
|
|
// target: "http://localhost:6060",
|