vue.config.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. publicPath: "/oe-web/",
  59. devServer: {
  60. proxy,
  61. },
  62. chainWebpack: config => {
  63. // iview Loader
  64. config.module
  65. .rule("vue")
  66. .test(/\.vue$/)
  67. .use("iview-loader")
  68. .loader("iview-loader")
  69. .options({
  70. prefix: true,
  71. })
  72. .end();
  73. },
  74. configureWebpack: {
  75. devtool: "source-map",
  76. plugins: [new webpack.IgnorePlugin(/^\.\/locale$/, /moment|iview$/)],
  77. },
  78. pwa: {
  79. workboxPluginMode: "GenerateSW",
  80. workboxOptions: {
  81. importWorkboxFrom: "local",
  82. // navigateFallback: "index.html",
  83. skipWaiting: true,
  84. clientsClaim: true,
  85. runtimeCaching: [
  86. {
  87. // 背景图如果要换,就改地址,减少网络消耗
  88. urlPattern: new RegExp(
  89. "^https://cdn.qmth.com.cn/ui/ecs-client-bg.jpg!/progressive/true"
  90. ),
  91. handler: "cacheFirst",
  92. options: {
  93. cacheableResponse: {
  94. statuses: [0, 200],
  95. },
  96. },
  97. },
  98. {
  99. // Match any same-origin request that contains 'api'.
  100. // 产品名称有可能每分钟都更新
  101. urlPattern: /\/api\/ecs_core\/org\/propertyNoSession\/OE_STUDENT_SYS_NAME\?domainName=/,
  102. handler: "cacheFirst",
  103. options: {
  104. cacheableResponse: {
  105. statuses: [0, 200],
  106. },
  107. cacheName: "sys-name-cache",
  108. expiration: {
  109. maxAgeSeconds: 60,
  110. },
  111. },
  112. },
  113. {
  114. // logo 地址会变
  115. urlPattern: new RegExp(
  116. "^https://ecs(-test)?-static.qmth.com.cn/org_logo/.*/.*"
  117. ),
  118. handler: "cacheFirst",
  119. options: {
  120. cacheableResponse: {
  121. statuses: [0, 200],
  122. },
  123. },
  124. },
  125. {
  126. // 作答文件的地址
  127. urlPattern: new RegExp(
  128. "^https://ecs(-test)?-static.qmth.com.cn/oe-answer-file/.*"
  129. ),
  130. handler: "cacheFirst",
  131. options: {
  132. cacheableResponse: {
  133. statuses: [0, 200],
  134. },
  135. cacheName: "oe-answer-file",
  136. expiration: {
  137. maxAgeSeconds: 4 * 60 * 60,
  138. },
  139. },
  140. },
  141. {
  142. urlPattern: /\/models\/.*\/.*\.json/,
  143. handler: "cacheFirst",
  144. options: {
  145. cacheableResponse: {
  146. statuses: [0, 200],
  147. },
  148. },
  149. },
  150. {
  151. // 客观分10分钟更新一次
  152. urlPattern: /\/api\/ecs_oe_student\/examScore\/queryObjectiveScoreList\?examStudentId=/,
  153. handler: "cacheFirst",
  154. options: {
  155. cacheableResponse: {
  156. statuses: [0, 200],
  157. },
  158. cacheName: "objective-score-list-cache",
  159. expiration: {
  160. maxAgeSeconds: 1 * 60,
  161. },
  162. },
  163. },
  164. {
  165. // APP是否下载1分钟更新一次
  166. urlPattern: /\/api\/ecs_core\/org\/property\/\d+\/APP_ENABLED/,
  167. handler: "cacheFirst",
  168. options: {
  169. cacheableResponse: {
  170. statuses: [0, 200],
  171. },
  172. cacheName: "app-alllow-download-cache",
  173. expiration: {
  174. maxAgeSeconds: 1 * 60,
  175. },
  176. },
  177. },
  178. {
  179. // APP下载地址10分钟更新一次
  180. urlPattern: /\/api\/ecs_core\/systemProperty\/APP_DOWNLOAD_URL/,
  181. handler: "cacheFirst",
  182. options: {
  183. cacheableResponse: {
  184. statuses: [0, 200],
  185. },
  186. cacheName: "app-download-url-cache",
  187. expiration: {
  188. maxAgeSeconds: 2 * 60,
  189. },
  190. },
  191. },
  192. {
  193. // 站内消息3分钟获取一次
  194. urlPattern: /\/api\/ecs_exam_work\/notice\/getUserNoticeList\?/,
  195. handler: "cacheFirst",
  196. options: {
  197. cacheableResponse: {
  198. statuses: [0, 200],
  199. },
  200. cacheName: "site-messages-list-cache",
  201. expiration: {
  202. maxAgeSeconds: 3 * 60,
  203. },
  204. },
  205. },
  206. {
  207. // 菜单3分钟获取一次
  208. urlPattern: /\/api\/ecs_core\/rolePrivilege\/getStudentClientMenu\?rootOrgId=/,
  209. handler: "cacheFirst",
  210. options: {
  211. cacheableResponse: {
  212. statuses: [0, 200],
  213. },
  214. cacheName: "menus-cache",
  215. expiration: {
  216. maxAgeSeconds: 3 * 60,
  217. },
  218. },
  219. },
  220. ],
  221. },
  222. },
  223. };