vite.config.ts 3.9 KB

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