vite.config.ts 4.1 KB

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