vue.config.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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:
  86. /\/api\/ecs_core\/org\/propertyNoSession\/OE_STUDENT_SYS_NAME\?domainName=/,
  87. handler: "cacheFirst",
  88. options: {
  89. cacheableResponse: {
  90. statuses: [0, 200],
  91. },
  92. cacheName: "sys-name-cache",
  93. expiration: {
  94. maxAgeSeconds: 60,
  95. },
  96. },
  97. },
  98. {
  99. // logo 地址会变
  100. urlPattern: new RegExp(
  101. "^https://ecs(-test)?-static.qmth.com.cn/org_logo/.*/.*"
  102. ),
  103. handler: "cacheFirst",
  104. options: {
  105. cacheableResponse: {
  106. statuses: [0, 200],
  107. },
  108. },
  109. },
  110. {
  111. // 作答文件的地址
  112. urlPattern: new RegExp(
  113. "^https://ecs(-test)?-static.qmth.com.cn/oe-answer-file/.*"
  114. ),
  115. handler: "cacheFirst",
  116. options: {
  117. cacheableResponse: {
  118. statuses: [0, 200],
  119. },
  120. cacheName: "oe-answer-file",
  121. expiration: {
  122. maxAgeSeconds: 4 * 60 * 60,
  123. },
  124. },
  125. },
  126. {
  127. urlPattern: /\/models\/.*\/.*\.json/,
  128. handler: "cacheFirst",
  129. options: {
  130. cacheableResponse: {
  131. statuses: [0, 200],
  132. },
  133. },
  134. },
  135. {
  136. // 客观分10分钟更新一次
  137. urlPattern:
  138. /\/api\/ecs_oe_student\/examScore\/queryObjectiveScoreList\?examStudentId=/,
  139. handler: "cacheFirst",
  140. options: {
  141. cacheableResponse: {
  142. statuses: [0, 200],
  143. },
  144. cacheName: "objective-score-list-cache",
  145. expiration: {
  146. maxAgeSeconds: 1 * 60,
  147. },
  148. },
  149. },
  150. {
  151. // APP是否下载1分钟更新一次
  152. urlPattern: /\/api\/ecs_core\/org\/property\/\d+\/APP_ENABLED/,
  153. handler: "cacheFirst",
  154. options: {
  155. cacheableResponse: {
  156. statuses: [0, 200],
  157. },
  158. cacheName: "app-alllow-download-cache",
  159. expiration: {
  160. maxAgeSeconds: 1 * 60,
  161. },
  162. },
  163. },
  164. {
  165. // APP下载地址10分钟更新一次
  166. urlPattern: /\/api\/ecs_core\/systemProperty\/APP_DOWNLOAD_URL/,
  167. handler: "cacheFirst",
  168. options: {
  169. cacheableResponse: {
  170. statuses: [0, 200],
  171. },
  172. cacheName: "app-download-url-cache",
  173. expiration: {
  174. maxAgeSeconds: 2 * 60,
  175. },
  176. },
  177. },
  178. {
  179. // 站内消息3分钟获取一次
  180. urlPattern: /\/api\/ecs_exam_work\/notice\/getUserNoticeList\?/,
  181. handler: "cacheFirst",
  182. options: {
  183. cacheableResponse: {
  184. statuses: [0, 200],
  185. },
  186. cacheName: "site-messages-list-cache",
  187. expiration: {
  188. maxAgeSeconds: 3 * 60,
  189. },
  190. },
  191. },
  192. {
  193. // 菜单3分钟获取一次
  194. urlPattern:
  195. /\/api\/ecs_core\/rolePrivilege\/getStudentClientMenu\?rootOrgId=/,
  196. handler: "cacheFirst",
  197. options: {
  198. cacheableResponse: {
  199. statuses: [0, 200],
  200. },
  201. cacheName: "menus-cache",
  202. expiration: {
  203. maxAgeSeconds: 3 * 60,
  204. },
  205. },
  206. },
  207. ],
  208. },
  209. },
  210. };