vite.config.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. // ".qmth.com.cn",
  79. // ".dev39.qmth.com.cn",
  80. // ".test41.qmth.com.cn",
  81. // ],
  82. domainLock: [],
  83. // selfDefending: true,
  84. // sourceMap: false,
  85. // splitStrings: true,
  86. disableConsoleOutput: false,
  87. // // stringArrayCallsTransform: true,
  88. // deadCodeInjection: true,
  89. // numbersToExpressions: true,
  90. controlFlowFlattening: true,
  91. // stringArrayEncoding: ["none", "base64", "rc4"],
  92. // stringArrayRotate: true,
  93. // transformObjectKeys: true,
  94. },
  95. include: [
  96. // "src/**/**.ts",
  97. // "src/**/**.js",
  98. "src/utils/**.ts",
  99. // "**/UserLogin/**.ts",
  100. // "**/Examing/**/**.ts",
  101. ],
  102. exclude: ["node_modules/**"],
  103. ...(disableObfuse
  104. ? {
  105. fileOptions: false,
  106. globalOptions: false,
  107. }
  108. : {}),
  109. }),
  110. ],
  111. server: {
  112. port: 3000,
  113. // strictPort: true,
  114. fs: {
  115. strict: true,
  116. allow: ["./"],
  117. },
  118. proxy: {
  119. "/api": {
  120. target: SERVER_URL,
  121. changeOrigin: true,
  122. secure: false,
  123. ws: true,
  124. },
  125. "/admin": {
  126. target: SERVER_URL,
  127. changeOrigin: true,
  128. secure: false,
  129. },
  130. },
  131. },
  132. resolve: {
  133. alias: [{ find: "@", replacement: path.resolve(__dirname, "./src") }],
  134. extensions: [
  135. ".js",
  136. ".mjs",
  137. ".ts",
  138. ".tsx",
  139. ".vue",
  140. ".json",
  141. ".scss",
  142. ".css",
  143. ],
  144. },
  145. build: {
  146. ssr: false,
  147. // FIXME: 为初期测试开启的调试
  148. sourcemap: !!disableObfuse,
  149. target: ["chrome58"],
  150. },
  151. // define: {
  152. // __VUE_PROD_DEVTOOLS__: true, // no effect
  153. // },
  154. });