vite.config.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { defineConfig, loadEnv } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import { resolve } from "path";
  4. // vue setup 的糖语法
  5. import VueSetupExtend from "vite-plugin-vue-setup-extend";
  6. // 不用导入 vue 的 import 了
  7. import AutoImport from "unplugin-auto-import/vite";
  8. import Icons from "unplugin-icons/vite";
  9. import vueJsx from "@vitejs/plugin-vue-jsx";
  10. import { createHtmlPlugin } from "vite-plugin-html";
  11. import pkg from "./package.json";
  12. import { codeInspectorPlugin } from "code-inspector-plugin";
  13. const pathResolve = dir => {
  14. return resolve(__dirname, ".", dir);
  15. };
  16. const alias = {
  17. "@": pathResolve("src"),
  18. };
  19. export default defineConfig(({ mode }) => {
  20. const ENV = loadEnv(mode, process.cwd());
  21. const GLOB_CONFIG_FILE_NAME = "_app.config.js";
  22. const isBuild = mode === "production";
  23. const getAppConfigSrc = () => {
  24. return `/${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`;
  25. };
  26. return {
  27. define: {
  28. __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "true",
  29. },
  30. esbuild: {
  31. jsxFactory: "h",
  32. jsxFragment: "Fragment",
  33. },
  34. externals: {
  35. BMap: "BMap",
  36. BMapLib: "BMapLib",
  37. },
  38. resolve: {
  39. alias: {
  40. ...alias,
  41. "vxe-pc-ui": pathResolve("node_modules/vxe-pc-ui"),
  42. "vxe-table": pathResolve("node_modules/vxe-table"),
  43. },
  44. // alias,
  45. extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
  46. },
  47. plugins: [
  48. codeInspectorPlugin({
  49. bundler: "vite",
  50. hideConsole: true,
  51. }),
  52. Icons({
  53. autoInstall: true,
  54. compiler: "vue3",
  55. }),
  56. VueSetupExtend({ name: false }),
  57. vue(),
  58. vueJsx(),
  59. AutoImport({
  60. dts: "src/auto-imports.d.ts",
  61. imports: ["vue"],
  62. }),
  63. createHtmlPlugin({
  64. minify: isBuild,
  65. inject: {
  66. data: {
  67. title: "",
  68. },
  69. // Embed the generated app.config.js file
  70. tags: isBuild
  71. ? [
  72. {
  73. tag: "script",
  74. attrs: {
  75. src: getAppConfigSrc(),
  76. },
  77. },
  78. ]
  79. : [],
  80. },
  81. }),
  82. ],
  83. server: {
  84. host: "0.0.0.0",
  85. port: 3000,
  86. proxy: {
  87. "/fuYou": {
  88. //这里配置运行时服务地址
  89. // target: "http://58.33.165.250:20011",
  90. target: "http://192.168.100.140:18080",
  91. secure: false, //如果运行时服务是https,此处配置为true
  92. changeOrigin: true, //支持跨域调用,这里配置为true
  93. rewrite: path => path.replace(/^\/fuYou/, ""),
  94. },
  95. "/emr": {
  96. //这里配置运行时服务地址
  97. target: "http://130.150.161.69:8001/emr",
  98. secure: false, //如果运行时服务是https,此处配置为true
  99. changeOrigin: true, //支持跨域调用,这里配置为true
  100. rewrite: path => path.replace(/^\/emr/, ""),
  101. },
  102. "/doctorSignatureImage": {
  103. target: "http://172.16.32.167:8077",
  104. secure: false, //如果运行时服务是https,此处配置为true
  105. changeOrigin: true, //支持跨域调用,这里配置为true
  106. },
  107. "/thyyarchive": {
  108. target: "http://172.16.32.197:9202/",
  109. secure: false,
  110. changeOrigin: true,
  111. rewrite: path => path.replace(/^\/thyyarchive/, ""),
  112. },
  113. },
  114. },
  115. build: {
  116. chunkSizeWarningLimit: 1000,
  117. outDir: "release/dist",
  118. // rollupOptions: {
  119. // output: {
  120. // manualChunks: {
  121. // // 将 vxe 相关库打包在一起
  122. // 'vxe-ui': ['vxe-pc-ui', 'vxe-table', 'vxe-table-plugin-export-xlsx']
  123. // }
  124. // }
  125. // }
  126. // 优化打包把第三方的东西每次打包时都不重复
  127. // rollupOptions: {
  128. // output: {
  129. // manualChunks(id) {
  130. // if (id.includes("node_modules")) {
  131. // return id
  132. // .toString()
  133. // .split("node_modules/")[1]
  134. // .split("/")[0]
  135. // .toString();
  136. // }
  137. // return null;
  138. // },
  139. // },
  140. // },
  141. },
  142. };
  143. });