From 8118f56d86267e443f147c17ccb014338607e247 Mon Sep 17 00:00:00 2001
From: haoxuan <haoxuan>
Date: 星期五, 18 八月 2023 20:26:18 +0800
Subject: [PATCH] 面板 前端开发+ 后端 没数据

---
 vue.config.js |  216 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 212 insertions(+), 4 deletions(-)

diff --git a/vue.config.js b/vue.config.js
index 910e297..ee75c91 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -1,4 +1,212 @@
-const { defineConfig } = require('@vue/cli-service')
-module.exports = defineConfig({
-  transpileDependencies: true
-})
+const CompressionWebpackPlugin = require("compression-webpack-plugin");
+const VueFilenameInjector = require("@d2-projects/vue-filename-injector");
+const ThemeColorReplacer = require("webpack-theme-color-replacer");
+const forElementUI = require("webpack-theme-color-replacer/forElementUI");
+const cdnDependencies = require("./dependencies-cdn");
+const { chain, set, each } = require("lodash");
+
+// 鎷兼帴璺緞
+const resolve = (dir) => require("path").join(__dirname, dir);
+
+// 澧炲姞鐜鍙橀噺
+process.env.VUE_APP_VERSION = require("./package.json").version;
+process.env.VUE_APP_BUILD_TIME = require("dayjs")().format("YYYY-M-D HH:mm:ss");
+
+// 鍩虹璺緞 娉ㄦ剰鍙戝竷涔嬪墠瑕佸厛淇敼杩欓噷
+const publicPath = process.env.VUE_APP_PUBLIC_PATH || "/";
+
+// 璁剧疆涓嶅弬涓庢瀯寤虹殑搴�
+const externals = {};
+cdnDependencies.forEach((pkg) => {
+  externals[pkg.name] = pkg.library;
+});
+
+// 寮曞叆鏂囦欢鐨� cdn 閾炬帴
+const cdn = {
+  css: cdnDependencies.map((e) => e.css).filter((e) => e),
+  js: cdnDependencies.map((e) => e.js).filter((e) => e),
+};
+
+// 澶氶〉閰嶇疆锛岄粯璁ゆ湭寮�鍚紝濡傞渶瑕佽鍙傝�� https://cli.vuejs.org/zh/config/#pages
+const pages = undefined;
+// const pages = {
+//   index: './src/main.js',
+//   subpage: './src/subpage.js'
+// }
+
+module.exports = {
+  // 鏍规嵁浣犵殑瀹為檯鎯呭喌鏇存敼杩欓噷
+
+  publicPath,
+  lintOnSave: true,
+  devServer: {
+    proxy: {
+      "/api/base": {
+        target: "http://192.168.20.119:8001",
+        ws: true,
+        changeOrigin: true,
+      },
+      "/api/user": {
+        target: "http://192.168.20.119:8001",
+        ws: true,
+        changeOrigin: true,
+      },
+      "/api/menu": {
+        target: "http://192.168.20.119:8001",
+        ws: true,
+        changeOrigin: true,
+      },
+      "/api-s": {
+        target: "http://192.168.20.119:9081",
+        ws: true,
+        changeOrigin: true,
+      },
+      "/api": {
+        target: "http://192.168.20.118:8001",
+        ws: true,
+        changeOrigin: true,
+      },
+      "/v1/task": {
+        target: "http://192.168.20.120:8003",
+        ws: true,
+        changeOrigin: true,
+      },
+      // "/api-s": {
+      //   target: "http://192.168.20.113:9081",
+      //   ws: true,
+      //   changeOrigin: true,
+      // },
+    },
+    publicPath, // 鍜� publicPath 淇濇寔涓�鑷�
+    disableHostCheck: process.env.NODE_ENV === "development", // 鍏抽棴 host check锛屾柟渚夸娇鐢� ngrok 涔嬬被鐨勫唴缃戣浆鍙戝伐鍏�
+  },
+  css: {
+    loaderOptions: {
+      // 璁剧疆 scss 鍏敤鍙橀噺鏂囦欢
+      sass: {
+        prependData: "@import '~@/assets/style/public.scss';",
+      },
+    },
+  },
+  pages,
+  configureWebpack: (config) => {
+    const configNew = {};
+    if (process.env.NODE_ENV === "production") {
+      configNew.externals = externals;
+      configNew.plugins = [
+        // gzip
+        new CompressionWebpackPlugin({
+          filename: "[path].gz[query]",
+          test: new RegExp("\\.(" + ["js", "css"].join("|") + ")$"),
+          threshold: 10240,
+          minRatio: 0.8,
+          deleteOriginalAssets: false,
+        }),
+      ];
+    }else if(process.env.NODE_ENV === "development"){
+
+    }
+    return configNew;
+  },
+  // 榛樿璁剧疆: https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-service/lib/config/base.js
+  chainWebpack: (config) => {
+    /**
+     * 娣诲姞 CDN 鍙傛暟鍒� htmlWebpackPlugin 閰嶇疆涓�
+     * 宸查�傞厤澶氶〉
+     */
+    const htmlPluginNames = chain(pages)
+      .keys()
+      .map((page) => "html-" + page)
+      .value();
+    const targetHtmlPluginNames = htmlPluginNames.length
+      ? htmlPluginNames
+      : ["html"];
+    each(targetHtmlPluginNames, (name) => {
+      config.plugin(name).tap((options) => {
+        set(
+          options,
+          "[0].cdn",
+          process.env.NODE_ENV === "production" ? cdn : []
+        );
+        return options;
+      });
+    });
+
+    /**
+     * 鍒犻櫎鎳掑姞杞芥ā鍧楃殑 prefetch preload锛岄檷浣庡甫瀹藉帇鍔�
+     * https://cli.vuejs.org/zh/guide/html-and-static-assets.html#prefetch
+     * https://cli.vuejs.org/zh/guide/html-and-static-assets.html#preload
+     * 鑰屼笖棰勬覆鏌撴椂鐢熸垚鐨� prefetch 鏍囩鏄� modern 鐗堟湰鐨勶紝浣庣増鏈祻瑙堝櫒鏄笉闇�瑕佺殑
+     */
+    config.plugins.delete("prefetch").delete("preload");
+    // 瑙e喅 cli3 鐑洿鏂板け鏁� https://github.com/vuejs/vue-cli/issues/1559
+    config.resolve.symlinks(true);
+    config.plugin("theme-color-replacer").use(ThemeColorReplacer, [
+      {
+        fileName: "css/theme-colors.[contenthash:8].css",
+        matchColors: [
+          ...forElementUI.getElementUISeries(process.env.VUE_APP_ELEMENT_COLOR), // Element-ui涓昏壊绯诲垪
+        ],
+        externalCssFiles: [
+          "./node_modules/element-ui/lib/theme-chalk/index.css",
+        ], // optional, String or string array. Set external css files (such as cdn css) to extract colors.
+        changeSelector: forElementUI.changeSelector,
+      },
+    ]);
+    config
+      // 寮�鍙戠幆澧� sourcemap 涓嶅寘鍚垪淇℃伅
+      .when(process.env.NODE_ENV === "development", (config) =>
+        config.devtool("cheap-source-map")
+      )
+      // 棰勮鐜鏋勫缓 vue-loader 娣诲姞 filename
+      .when(process.env.VUE_APP_SCOURCE_LINK === "TRUE", (config) =>
+        VueFilenameInjector(config, {
+          propName: process.env.VUE_APP_SOURCE_VIEWER_PROP_NAME,
+        })
+      );
+    // markdown
+    config.module
+      .rule("md")
+      .test(/\.md$/)
+      .use("text-loader")
+      .loader("text-loader")
+      .end();
+    // svg
+    const svgRule = config.module.rule("svg");
+    svgRule.uses.clear();
+    svgRule.include
+      .add(resolve("src/assets/svg-icons/icons"))
+      .end()
+      .use("svg-sprite-loader")
+      .loader("svg-sprite-loader")
+      .options({
+        symbolId: "d2-[name]",
+      })
+      .end();
+    // image exclude
+    const imagesRule = config.module.rule("images");
+    imagesRule
+      .test(/\.(png|jpe?g|gif|webp|svg)(\?.*)?$/)
+      .exclude.add(resolve("src/assets/svg-icons/icons"))
+      .end();
+    // 閲嶆柊璁剧疆 alias
+    config.resolve.alias.set("@api", resolve("src/api"));
+    // 鍒嗘瀽宸ュ叿
+    if (process.env.npm_config_report) {
+      config
+        .plugin("webpack-bundle-analyzer")
+        .use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin);
+    }
+  },
+  // 涓嶈緭鍑� map 鏂囦欢
+  productionSourceMap: false,
+  // i18n
+  pluginOptions: {
+    i18n: {
+      locale: "zh-chs",
+      fallbackLocale: "en",
+      localeDir: "locales",
+      enableInSFC: true,
+    },
+  },
+};

--
Gitblit v1.8.0