vite.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. const pathResolve = dir => {
  13. return resolve(__dirname, ".", dir);
  14. };
  15. const alias = {
  16. "@": pathResolve("src"),
  17. };
  18. export default defineConfig(({ mode }) => {
  19. const ENV = loadEnv(mode, process.cwd());
  20. const GLOB_CONFIG_FILE_NAME = "_app.config.js";
  21. const isBuild = mode === "production";
  22. const getAppConfigSrc = () => {
  23. return `/${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`;
  24. };
  25. return {
  26. define: {
  27. __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "true",
  28. },
  29. esbuild: {
  30. jsxFactory: "h",
  31. jsxFragment: "Fragment",
  32. },
  33. externals: {
  34. BMap: "BMap",
  35. BMapLib: "BMapLib",
  36. },
  37. resolve: {
  38. alias,
  39. extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
  40. },
  41. plugins: [
  42. Icons({
  43. autoInstall: true,
  44. compiler: "vue3",
  45. }),
  46. VueSetupExtend({ name: false }),
  47. vue(),
  48. vueJsx(),
  49. AutoImport({
  50. dts: "src/auto-imports.d.ts",
  51. imports: ["vue"],
  52. }),
  53. createHtmlPlugin({
  54. minify: isBuild,
  55. inject: {
  56. data: {
  57. title: "",
  58. },
  59. // Embed the generated app.config.js file
  60. tags: isBuild
  61. ? [
  62. {
  63. tag: "script",
  64. attrs: {
  65. src: getAppConfigSrc(),
  66. },
  67. },
  68. ]
  69. : [],
  70. },
  71. }),
  72. ],
  73. server: {
  74. host: "0.0.0.0",
  75. port: 3000,
  76. proxy: {
  77. "/emr": {
  78. //这里配置运行时服务地址
  79. target: "http://172.16.32.125:8001/emr",
  80. secure: false, //如果运行时服务是https,此处配置为true
  81. changeOrigin: true, //支持跨域调用,这里配置为true
  82. rewrite: path => path.replace(/^\/emr/, ""),
  83. },
  84. "/doctorSignatureImage": {
  85. target: "http://172.16.32.167:8077",
  86. secure: false, //如果运行时服务是https,此处配置为true
  87. changeOrigin: true, //支持跨域调用,这里配置为true
  88. },
  89. "/thyyarchive": {
  90. target: "http://172.16.32.197:9202/",
  91. secure: false,
  92. changeOrigin: true,
  93. rewrite: path => path.replace(/^\/thyyarchive/, ""),
  94. },
  95. },
  96. },
  97. build: {
  98. chunkSizeWarningLimit: 1000,
  99. outDir: "release/dist",
  100. // 优化打包把第三方的东西每次打包时都不重复
  101. // rollupOptions: {
  102. // output: {
  103. // manualChunks(id) {
  104. // if (id.includes("node_modules")) {
  105. // return id
  106. // .toString()
  107. // .split("node_modules/")[1]
  108. // .split("/")[0]
  109. // .toString();
  110. // }
  111. // return null;
  112. // },
  113. // },
  114. // },
  115. },
  116. };
  117. });