123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- let proxy = {
- "/api": {
- target: process.env.VUE_APP_CORE_HOST_URL,
- changeOrigin: true,
- ws: true,
- },
- };
- const fs = require("fs");
- if (fs.existsSync("./proxy.config.js")) {
- // 项目根目录下,创建 proxy.config.js,内容如下。把需要代理到本地服务器的api添加到下面。
- // exports.default = {
- // "/api/test": {
- // target: "http://localhost:8001",
- // changeOrigin: true,
- // ws: true,
- // },
- // };
- const localProxy = require("./proxy.config.js").default;
- proxy = { ...localProxy, ...proxy };
- console.log(proxy);
- }
- // const mock = [{ source: "/api/mock/exam_question", dest: "/examQuestions" }];
- // for (const m of mock) {
- // proxy[m.source] = {
- // target: "http://localhost:3000/",
- // changeOrigin: true,
- // pathRewrite: {
- // ".*": m.dest
- // }
- // };
- // }
- var webpack = require("webpack");
- // const plugins = [];
- // Ignore all locale files of moment.js
- // TODO: use webpack stats to check if iview locale matters
- // plugins.push();
- // if (process.env.NODE_ENV === "production") {
- // plugins.push("transform-remove-console");
- // }
- module.exports = {
- lintOnSave: process.env.NODE_ENV !== "production" ? true : "error",
- publicPath: process.env.VUE_APP_PUBLIC_PATH,
- devServer: {
- proxy,
- },
- chainWebpack: (config) => {
- // iview Loader
- config.module
- .rule("vue")
- .test(/\.vue$/)
- .use("iview-loader")
- .loader("iview-loader")
- .options({
- prefix: true,
- })
- .end();
- },
- configureWebpack: {
- devtool: "source-map",
- plugins: [new webpack.IgnorePlugin(/^\.\/locale$/, /moment|iview$/)],
- },
- pwa: {
- workboxPluginMode: "GenerateSW",
- workboxOptions: {
- importWorkboxFrom: "local",
- // navigateFallback: "index.html",
- skipWaiting: true,
- clientsClaim: true,
- runtimeCaching: [
- {
- // 背景图如果要换,就改地址,减少网络消耗
- urlPattern: new RegExp(
- "^https://cdn.qmth.com.cn/ui/ecs-client-bg.jpg!/progressive/true"
- ),
- handler: "cacheFirst",
- options: {
- cacheableResponse: {
- statuses: [0, 200],
- },
- },
- },
- {
- // Match any same-origin request that contains 'api'.
- // 产品名称有可能每分钟都更新
- urlPattern: /\/api\/ecs_core\/org\/propertyNoSession\/OE_STUDENT_SYS_NAME\?domainName=/,
- handler: "cacheFirst",
- options: {
- cacheableResponse: {
- statuses: [0, 200],
- },
- cacheName: "sys-name-cache",
- expiration: {
- maxAgeSeconds: 60,
- },
- },
- },
- {
- // logo 地址会变
- urlPattern: new RegExp(
- "^https://ecs(-test)?-static.qmth.com.cn/org_logo/.*/.*"
- ),
- handler: "cacheFirst",
- options: {
- cacheableResponse: {
- statuses: [0, 200],
- },
- },
- },
- {
- // 作答文件的地址
- urlPattern: new RegExp(
- "^https://ecs(-test)?-static.qmth.com.cn/oe-answer-file/.*"
- ),
- handler: "cacheFirst",
- options: {
- cacheableResponse: {
- statuses: [0, 200],
- },
- cacheName: "oe-answer-file",
- expiration: {
- maxAgeSeconds: 4 * 60 * 60,
- },
- },
- },
- {
- urlPattern: /\/models\/.*\/.*\.json/,
- handler: "cacheFirst",
- options: {
- cacheableResponse: {
- statuses: [0, 200],
- },
- },
- },
- {
- // 客观分10分钟更新一次
- urlPattern: /\/api\/ecs_oe_student\/examScore\/queryObjectiveScoreList\?examStudentId=/,
- handler: "cacheFirst",
- options: {
- cacheableResponse: {
- statuses: [0, 200],
- },
- cacheName: "objective-score-list-cache",
- expiration: {
- maxAgeSeconds: 1 * 60,
- },
- },
- },
- {
- // APP是否下载1分钟更新一次
- urlPattern: /\/api\/ecs_core\/org\/property\/\d+\/APP_ENABLED/,
- handler: "cacheFirst",
- options: {
- cacheableResponse: {
- statuses: [0, 200],
- },
- cacheName: "app-alllow-download-cache",
- expiration: {
- maxAgeSeconds: 1 * 60,
- },
- },
- },
- {
- // APP下载地址10分钟更新一次
- urlPattern: /\/api\/ecs_core\/systemProperty\/APP_DOWNLOAD_URL/,
- handler: "cacheFirst",
- options: {
- cacheableResponse: {
- statuses: [0, 200],
- },
- cacheName: "app-download-url-cache",
- expiration: {
- maxAgeSeconds: 2 * 60,
- },
- },
- },
- {
- // 站内消息3分钟获取一次
- urlPattern: /\/api\/ecs_exam_work\/notice\/getUserNoticeList\?/,
- handler: "cacheFirst",
- options: {
- cacheableResponse: {
- statuses: [0, 200],
- },
- cacheName: "site-messages-list-cache",
- expiration: {
- maxAgeSeconds: 3 * 60,
- },
- },
- },
- {
- // 菜单3分钟获取一次
- urlPattern: /\/api\/ecs_core\/rolePrivilege\/getStudentClientMenu\?rootOrgId=/,
- handler: "cacheFirst",
- options: {
- cacheableResponse: {
- statuses: [0, 200],
- },
- cacheName: "menus-cache",
- expiration: {
- maxAgeSeconds: 3 * 60,
- },
- },
- },
- ],
- },
- },
- };
|