vue.config.js 4.6 KB

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