vue.config.js 5.7 KB

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