vite.config.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import { defineConfig, loadEnv } 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 env = loadEnv("development", process.cwd(), "");
  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. // javascriptObfuscator({
  111. // compact: true,
  112. // controlFlowFlattening: true,
  113. // controlFlowFlatteningThreshold: 1,
  114. // deadCodeInjection: true,
  115. // deadCodeInjectionThreshold: 1,
  116. // debugProtection: true,
  117. // debugProtectionInterval: 0,
  118. // disableConsoleOutput: true,
  119. // identifierNamesGenerator: "hexadecimal",
  120. // log: false,
  121. // renameGlobals: false,
  122. // rotateStringArray: true,
  123. // selfDefending: true,
  124. // shuffleStringArray: true,
  125. // splitStrings: true,
  126. // splitStringsChunkLength: 10,
  127. // stringArray: true,
  128. // stringArrayEncoding: ["rc4"],
  129. // stringArrayThreshold: 1,
  130. // transformObjectKeys: true,
  131. // unicodeEscapeSequence: false,
  132. // }),
  133. ],
  134. server: {
  135. port: 9030,
  136. // strictPort: true,
  137. fs: {
  138. strict: true,
  139. allow: ["./"],
  140. },
  141. proxy: {
  142. "/api": {
  143. target: env.VUE_APP_DEV_PROXY,
  144. changeOrigin: true,
  145. secure: false,
  146. ws: false,
  147. },
  148. "/admin": {
  149. target: env.VUE_APP_DEV_PROXY,
  150. changeOrigin: true,
  151. secure: false,
  152. },
  153. },
  154. },
  155. resolve: {
  156. alias: [{ find: "@", replacement: path.resolve(__dirname, "./src") }],
  157. extensions: [
  158. ".js",
  159. ".mjs",
  160. ".ts",
  161. ".tsx",
  162. ".vue",
  163. ".json",
  164. ".scss",
  165. ".css",
  166. ],
  167. },
  168. build: {
  169. ssr: false,
  170. // FIXME: 为初期测试开启的调试
  171. sourcemap: !!disableObfuse,
  172. target: ["chrome58"],
  173. },
  174. // define: {
  175. // __VUE_PROD_DEVTOOLS__: true, // no effect
  176. // },
  177. });