import { defineConfig, loadEnv } from "vite"; import vue from "@vitejs/plugin-vue"; import { resolve } from "path"; // vue setup 的糖语法 import VueSetupExtend from "vite-plugin-vue-setup-extend"; // 不用导入 vue 的 import 了 import AutoImport from "unplugin-auto-import/vite"; import Icons from "unplugin-icons/vite"; import vueJsx from "@vitejs/plugin-vue-jsx"; import { createHtmlPlugin } from "vite-plugin-html"; import pkg from "./package.json"; import { codeInspectorPlugin } from "code-inspector-plugin"; const pathResolve = dir => { return resolve(__dirname, ".", dir); }; const alias = { "@": pathResolve("src"), }; export default defineConfig(({ mode }) => { const ENV = loadEnv(mode, process.cwd()); const GLOB_CONFIG_FILE_NAME = "_app.config.js"; const isBuild = mode === "production"; const getAppConfigSrc = () => { return `/${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`; }; return { define: { __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "true", }, esbuild: { jsxFactory: "h", jsxFragment: "Fragment", }, externals: { BMap: "BMap", BMapLib: "BMapLib", }, resolve: { alias: { ...alias, "vxe-pc-ui": pathResolve("node_modules/vxe-pc-ui"), "vxe-table": pathResolve("node_modules/vxe-table"), }, // alias, extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"], }, plugins: [ codeInspectorPlugin({ bundler: "vite", hideConsole: true, }), Icons({ autoInstall: true, compiler: "vue3", }), VueSetupExtend({ name: false }), vue(), vueJsx(), AutoImport({ dts: "src/auto-imports.d.ts", imports: ["vue"], }), createHtmlPlugin({ minify: isBuild, inject: { data: { title: "", }, // Embed the generated app.config.js file tags: isBuild ? [ { tag: "script", attrs: { src: getAppConfigSrc(), }, }, ] : [], }, }), ], server: { host: "0.0.0.0", port: 3000, proxy: { "/emr": { //这里配置运行时服务地址 target: "http://130.150.161.69:8001/emr", secure: false, //如果运行时服务是https,此处配置为true changeOrigin: true, //支持跨域调用,这里配置为true rewrite: path => path.replace(/^\/emr/, ""), }, "/doctorSignatureImage": { target: "http://172.16.32.167:8077", secure: false, //如果运行时服务是https,此处配置为true changeOrigin: true, //支持跨域调用,这里配置为true }, "/thyyarchive": { target: "http://172.16.32.197:9202/", secure: false, changeOrigin: true, rewrite: path => path.replace(/^\/thyyarchive/, ""), }, }, }, build: { chunkSizeWarningLimit: 1000, outDir: "release/dist", // rollupOptions: { // output: { // manualChunks: { // // 将 vxe 相关库打包在一起 // 'vxe-ui': ['vxe-pc-ui', 'vxe-table', 'vxe-table-plugin-export-xlsx'] // } // } // } // 优化打包把第三方的东西每次打包时都不重复 // rollupOptions: { // output: { // manualChunks(id) { // if (id.includes("node_modules")) { // return id // .toString() // .split("node_modules/")[1] // .split("/")[0] // .toString(); // } // return null; // }, // }, // }, }, }; });