vite.config.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import { defineConfig } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import Components from "unplugin-vue-components/vite";
  4. import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
  5. import AutoImport from "unplugin-auto-import/vite";
  6. import legacy from "@vitejs/plugin-legacy";
  7. import vueJsx from "@vitejs/plugin-vue-jsx";
  8. // import obfuscator from "rollup-plugin-obfuscator";
  9. // const SERVER_URL = "https://192.168.10.240";
  10. // const SERVER_URL = "https://192.168.10.39";
  11. const SERVER_URL = "https://192.168.10.41";
  12. const path = require("path");
  13. const disableObfuse = process.env.DISABLE_OBFUSE;
  14. // console.log(process.env);
  15. // console.log(disableObfuse);
  16. console.log("process.env.DISABLE_OBFUSE: ", disableObfuse);
  17. // https://vitejs.dev/config/
  18. export default defineConfig({
  19. base: "/oe-web/",
  20. plugins: [
  21. vue({ reactivityTransform: true }),
  22. vueJsx({}),
  23. Components({
  24. resolvers: [NaiveUiResolver()],
  25. dts: "src/types/components.d.ts",
  26. }),
  27. AutoImport({
  28. // targets to transform
  29. include: [
  30. /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
  31. /\.vue$/,
  32. /\.vue\?vue/, // .vue
  33. ],
  34. resolvers: [(name) => (name === "logger" ? "@/utils/logger" : undefined)],
  35. dts: "src/types/auto-imports.d.ts",
  36. // Generate corresponding .eslintrc-auto-import.json file.
  37. // eslint globals Docs - https://eslint.org/docs/user-guide/configuring/language-options#specifying-globals
  38. eslintrc: {
  39. enabled: true, // Default `false`
  40. filepath: "./.eslintrc-auto-import.json", // Default `./.eslintrc-auto-import.json`
  41. globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
  42. },
  43. }),
  44. legacy({
  45. targets: ["chrome >= 58"],
  46. additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
  47. }),
  48. // process.env.NODE_ENV === "development"
  49. // ? {}
  50. // : // : obfuscator({
  51. // // 不同的构建可能成功运行也可能不成功?
  52. // // 看看是不是单个文件做transform,然后对最终文件做renderChunk导致的构建结果不一致
  53. // fileOptions: false,
  54. // // fileOptions: {
  55. // // optionsPreset: "low-obfuscation",
  56. // // debugProtection: false,
  57. // // transformObjectKeys: false,
  58. // // disableConsoleOutput: false,
  59. // // // controlFlowFlattening: true,
  60. // // controlFlowFlatteningThreshold: 0.9,
  61. // // // per-file:
  62. // // deadCodeInjection: true,
  63. // // deadCodeInjectionThreshold: 1,
  64. // // // stringArrayThreshold: 1,
  65. // // // numbersToExpressions: true,
  66. // // // controlFlowFlatteningThreshold: 1,
  67. // // // stringArrayCallsTransform: true,
  68. // // // stringArrayCallsTransformThreshold: 1,
  69. // // // stringArrayEncoding: ["rc4"],
  70. // // },
  71. // globalOptions: {
  72. // optionsPreset: "low-obfuscation",
  73. // // debugProtection: true,
  74. // // debugProtectionInterval: 2000,
  75. // // domainLock: [
  76. // // ".exam-cloud.cn",
  77. // // ".test41v3.qmth.com.cn",
  78. // // ".ea100.com.cn",
  79. // // ".ecs.qmth.com.cn",
  80. // // ".qmth.com.cn",
  81. // // ".dev39.qmth.com.cn",
  82. // // ".test41.qmth.com.cn",
  83. // // ],
  84. // domainLock: [],
  85. // // selfDefending: true,
  86. // // sourceMap: false,
  87. // // splitStrings: true,
  88. // disableConsoleOutput: false,
  89. // // // stringArrayCallsTransform: true,
  90. // // deadCodeInjection: true,
  91. // // numbersToExpressions: true,
  92. // controlFlowFlattening: true,
  93. // // stringArrayEncoding: ["none", "base64", "rc4"],
  94. // // stringArrayRotate: true,
  95. // // transformObjectKeys: true,
  96. // },
  97. // include: [
  98. // // "src/**/**.ts",
  99. // // "src/**/**.js",
  100. // "src/utils/**.ts",
  101. // // "**/UserLogin/**.ts",
  102. // // "**/Examing/**/**.ts",
  103. // ],
  104. // exclude: ["node_modules/**"],
  105. // ...(disableObfuse
  106. // ? {
  107. // fileOptions: false,
  108. // globalOptions: false,
  109. // }
  110. // : {}),
  111. // }),
  112. // javascriptObfuscator({
  113. // compact: true,
  114. // controlFlowFlattening: true,
  115. // controlFlowFlatteningThreshold: 1,
  116. // deadCodeInjection: true,
  117. // deadCodeInjectionThreshold: 1,
  118. // debugProtection: true,
  119. // debugProtectionInterval: 0,
  120. // disableConsoleOutput: true,
  121. // identifierNamesGenerator: "hexadecimal",
  122. // log: false,
  123. // renameGlobals: false,
  124. // rotateStringArray: true,
  125. // selfDefending: true,
  126. // shuffleStringArray: true,
  127. // splitStrings: true,
  128. // splitStringsChunkLength: 10,
  129. // stringArray: true,
  130. // stringArrayEncoding: ["rc4"],
  131. // stringArrayThreshold: 1,
  132. // transformObjectKeys: true,
  133. // unicodeEscapeSequence: false,
  134. // }),
  135. ],
  136. server: {
  137. port: 3000,
  138. // strictPort: true,
  139. fs: {
  140. strict: true,
  141. allow: ["./"],
  142. },
  143. proxy: {
  144. "/api": {
  145. target: SERVER_URL,
  146. changeOrigin: true,
  147. secure: false,
  148. ws: false,
  149. },
  150. "/admin": {
  151. target: SERVER_URL,
  152. changeOrigin: true,
  153. secure: false,
  154. },
  155. },
  156. },
  157. resolve: {
  158. alias: [{ find: "@", replacement: path.resolve(__dirname, "./src") }],
  159. extensions: [
  160. ".js",
  161. ".mjs",
  162. ".ts",
  163. ".tsx",
  164. ".vue",
  165. ".json",
  166. ".scss",
  167. ".css",
  168. ],
  169. },
  170. build: {
  171. ssr: false,
  172. // FIXME: 为初期测试开启的调试
  173. sourcemap: !!disableObfuse,
  174. target: ["chrome58"],
  175. },
  176. // define: {
  177. // __VUE_PROD_DEVTOOLS__: true, // no effect
  178. // },
  179. });