vite.config.ts 4.7 KB

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