vue.config.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. let proxy = {
  2. "/api/ecs_oe_admin": {
  3. target:
  4. process.env.VUE_APP_OE_ADMIN_HOST_URL ||
  5. process.env.VUE_APP_CORE_HOST_URL,
  6. changeOrigin: true,
  7. },
  8. "/api/ecs_oe_student": {
  9. target:
  10. process.env.VUE_APP_OE_STUDENT_HOST_URL ||
  11. process.env.VUE_APP_CORE_HOST_URL,
  12. changeOrigin: true,
  13. },
  14. "/api": {
  15. target: process.env.VUE_APP_CORE_HOST_URL,
  16. changeOrigin: true,
  17. ws: true,
  18. },
  19. };
  20. // const stu = [
  21. // "/api/ecs_oe",
  22. // "/api/ecs_oe_student/",
  23. // "/api/sys_param",
  24. // "/api/exam_record",
  25. // "/api/exam_control",
  26. // "/api/exam_question",
  27. // "/api/exam_score",
  28. // "/api/practice_course",
  29. // "/api/practice_detail",
  30. // "/api/practice_record",
  31. // "/api/exam_captures",
  32. // "/api/face_capture",
  33. // "/api/face_verify",
  34. // "/api/offline_exam"
  35. // ];
  36. // for (const s of stu) {
  37. // proxy[s] = {
  38. // target: "http://ecs-dev.qmth.com.cn:8003", // 陈恳
  39. // changeOrigin: true
  40. // };
  41. // }
  42. // const mock = [{ source: "/api/mock/exam_question", dest: "/examQuestions" }];
  43. // for (const m of mock) {
  44. // proxy[m.source] = {
  45. // target: "http://localhost:3000/",
  46. // changeOrigin: true,
  47. // pathRewrite: {
  48. // ".*": m.dest
  49. // }
  50. // };
  51. // }
  52. var webpack = require("webpack");
  53. // const plugins = [];
  54. // Ignore all locale files of moment.js
  55. // TODO: use webpack stats to check if iview locale matters
  56. // plugins.push();
  57. // if (process.env.NODE_ENV === "production") {
  58. // plugins.push("transform-remove-console");
  59. // }
  60. module.exports = {
  61. lintOnSave: process.env.NODE_ENV !== "production" ? true : "error",
  62. publicPath: process.env.VUE_APP_PUBLIC_PATH,
  63. devServer: {
  64. proxy,
  65. },
  66. chainWebpack: (config) => {
  67. // iview Loader
  68. config.module
  69. .rule("vue")
  70. .test(/\.vue$/)
  71. .use("iview-loader")
  72. .loader("iview-loader")
  73. .options({
  74. prefix: true,
  75. })
  76. .end();
  77. },
  78. configureWebpack: {
  79. devtool: "source-map",
  80. plugins: [new webpack.IgnorePlugin(/^\.\/locale$/, /moment|iview$/)],
  81. },
  82. pwa: {
  83. workboxPluginMode: "GenerateSW",
  84. workboxOptions: {
  85. importWorkboxFrom: "local",
  86. // navigateFallback: "index.html",
  87. skipWaiting: true,
  88. clientsClaim: true,
  89. runtimeCaching: [
  90. {
  91. // 背景图如果要换,就改地址,减少网络消耗
  92. urlPattern: new RegExp(
  93. "^https://cdn.qmth.com.cn/ui/ecs-client-bg.jpg!/progressive/true"
  94. ),
  95. handler: "cacheFirst",
  96. options: {
  97. cacheableResponse: {
  98. statuses: [0, 200],
  99. },
  100. },
  101. },
  102. {
  103. // Match any same-origin request that contains 'api'.
  104. // 产品名称有可能每分钟都更新
  105. urlPattern: /\/api\/ecs_core\/org\/propertyNoSession\/OE_STUDENT_SYS_NAME\?domainName=/,
  106. handler: "cacheFirst",
  107. options: {
  108. cacheableResponse: {
  109. statuses: [0, 200],
  110. },
  111. cacheName: "sys-name-cache",
  112. expiration: {
  113. maxAgeSeconds: 60,
  114. },
  115. },
  116. },
  117. {
  118. // logo 地址会变
  119. urlPattern: new RegExp(
  120. "^https://ecs(-test)?-static.qmth.com.cn/org_logo/.*/.*"
  121. ),
  122. handler: "cacheFirst",
  123. options: {
  124. cacheableResponse: {
  125. statuses: [0, 200],
  126. },
  127. },
  128. },
  129. {
  130. // 作答文件的地址
  131. urlPattern: new RegExp(
  132. "^https://ecs(-test)?-static.qmth.com.cn/oe-answer-file/.*"
  133. ),
  134. handler: "cacheFirst",
  135. options: {
  136. cacheableResponse: {
  137. statuses: [0, 200],
  138. },
  139. cacheName: "oe-answer-file",
  140. expiration: {
  141. maxAgeSeconds: 4 * 60 * 60,
  142. },
  143. },
  144. },
  145. {
  146. urlPattern: /\/models\/.*\/.*\.json/,
  147. handler: "cacheFirst",
  148. options: {
  149. cacheableResponse: {
  150. statuses: [0, 200],
  151. },
  152. },
  153. },
  154. {
  155. // 客观分10分钟更新一次
  156. urlPattern: /\/api\/ecs_oe_student\/examScore\/queryObjectiveScoreList\?examStudentId=/,
  157. handler: "cacheFirst",
  158. options: {
  159. cacheableResponse: {
  160. statuses: [0, 200],
  161. },
  162. cacheName: "objective-score-list-cache",
  163. expiration: {
  164. maxAgeSeconds: 1 * 60,
  165. },
  166. },
  167. },
  168. {
  169. // APP是否下载1分钟更新一次
  170. urlPattern: /\/api\/ecs_core\/org\/property\/\d+\/APP_ENABLED/,
  171. handler: "cacheFirst",
  172. options: {
  173. cacheableResponse: {
  174. statuses: [0, 200],
  175. },
  176. cacheName: "app-alllow-download-cache",
  177. expiration: {
  178. maxAgeSeconds: 1 * 60,
  179. },
  180. },
  181. },
  182. {
  183. // APP下载地址10分钟更新一次
  184. urlPattern: /\/api\/ecs_core\/systemProperty\/APP_DOWNLOAD_URL/,
  185. handler: "cacheFirst",
  186. options: {
  187. cacheableResponse: {
  188. statuses: [0, 200],
  189. },
  190. cacheName: "app-download-url-cache",
  191. expiration: {
  192. maxAgeSeconds: 2 * 60,
  193. },
  194. },
  195. },
  196. {
  197. // 站内消息3分钟获取一次
  198. urlPattern: /\/api\/ecs_exam_work\/notice\/getUserNoticeList\?/,
  199. handler: "cacheFirst",
  200. options: {
  201. cacheableResponse: {
  202. statuses: [0, 200],
  203. },
  204. cacheName: "site-messages-list-cache",
  205. expiration: {
  206. maxAgeSeconds: 3 * 60,
  207. },
  208. },
  209. },
  210. {
  211. // 菜单3分钟获取一次
  212. urlPattern: /\/api\/ecs_core\/rolePrivilege\/getStudentClientMenu\?rootOrgId=/,
  213. handler: "cacheFirst",
  214. options: {
  215. cacheableResponse: {
  216. statuses: [0, 200],
  217. },
  218. cacheName: "menus-cache",
  219. expiration: {
  220. maxAgeSeconds: 3 * 60,
  221. },
  222. },
  223. },
  224. ],
  225. },
  226. },
  227. };