vue.config.js 5.6 KB

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