vite.config.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. "/emr": {
  88. //这里配置运行时服务地址
  89. target: "http://130.150.161.69:8001/emr",
  90. secure: false, //如果运行时服务是https,此处配置为true
  91. changeOrigin: true, //支持跨域调用,这里配置为true
  92. rewrite: path => path.replace(/^\/emr/, ""),
  93. },
  94. "/doctorSignatureImage": {
  95. target: "http://172.16.32.167:8077",
  96. secure: false, //如果运行时服务是https,此处配置为true
  97. changeOrigin: true, //支持跨域调用,这里配置为true
  98. },
  99. "/thyyarchive": {
  100. target: "http://172.16.32.197:9202/",
  101. secure: false,
  102. changeOrigin: true,
  103. rewrite: path => path.replace(/^\/thyyarchive/, ""),
  104. },
  105. },
  106. },
  107. build: {
  108. chunkSizeWarningLimit: 1000,
  109. outDir: "release/dist",
  110. // rollupOptions: {
  111. // output: {
  112. // manualChunks: {
  113. // // 将 vxe 相关库打包在一起
  114. // 'vxe-ui': ['vxe-pc-ui', 'vxe-table', 'vxe-table-plugin-export-xlsx']
  115. // }
  116. // }
  117. // }
  118. // 优化打包把第三方的东西每次打包时都不重复
  119. // rollupOptions: {
  120. // output: {
  121. // manualChunks(id) {
  122. // if (id.includes("node_modules")) {
  123. // return id
  124. // .toString()
  125. // .split("node_modules/")[1]
  126. // .split("/")[0]
  127. // .toString();
  128. // }
  129. // return null;
  130. // },
  131. // },
  132. // },
  133. },
  134. };
  135. });