vue.config.js 5.5 KB

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