vite.config.ts 4.7 KB

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