vue.config.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. const path = require("path");
  2. const webpack = require("webpack");
  3. const GitRevisionPlugin = require("git-revision-webpack-plugin");
  4. const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
  5. const GitRevision = new GitRevisionPlugin();
  6. const buildDate = JSON.stringify(new Date().toLocaleString());
  7. const createThemeColorReplacerPlugin = require("./config/plugin.config");
  8. const theme = require("./src/config/theme.config");
  9. const MonacoWebpackPlugin = require("monaco-editor-webpack-plugin");
  10. // const serverCongfig = require('./src/config/serviceSettings')
  11. const webpackPlatformSetting = require("plg-platform-setting/webpack-plugin");
  12. function resolve(dir) {
  13. return path.join(__dirname, dir);
  14. }
  15. // check Git
  16. function getGitHash() {
  17. try {
  18. return GitRevision.version();
  19. } catch (e) {}
  20. return "unknown";
  21. }
  22. const isProd = process.env.NODE_ENV === "production";
  23. const assetsCDN = {
  24. // webpack build externals
  25. externals: {
  26. vue: "Vue",
  27. "vue-router": "VueRouter",
  28. vuex: "Vuex",
  29. axios: "axios",
  30. },
  31. css: [],
  32. js: [
  33. "//cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js",
  34. "//cdn.jsdelivr.net/npm/vue-router@3.5.2/dist/vue-router.min.js",
  35. "//cdn.jsdelivr.net/npm/vuex@3.6.2/dist/vuex.min.js",
  36. "//cdn.jsdelivr.net/npm/axios@0.19.0/dist/axios.min.js",
  37. //at.alicdn.com/t/font_1780424_92kpfp3gue7.js
  38. ],
  39. };
  40. const defaultPlugins = [
  41. // Ignore all locale files of moment.js
  42. new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  43. new webpack.DefinePlugin({
  44. APP_VERSION: `"${require("./package.json").version}"`,
  45. GIT_HASH: JSON.stringify(getGitHash()),
  46. BUILD_DATE: buildDate,
  47. }),
  48. new MonacoWebpackPlugin({
  49. languages: ["javascript", "css", "html", "json", "sql"],
  50. features: ["coreCommands", "find"],
  51. }),
  52. // createThemeColorReplacerPlugin(),
  53. new webpackPlatformSetting(),
  54. ];
  55. /**依赖大小分析工具 npm run build:preview */
  56. process.env.MODE == "preview" ? defaultPlugins.push(new BundleAnalyzerPlugin()) : null;
  57. // vue.config.js
  58. const vueConfig = {
  59. configureWebpack: {
  60. // webpack plugins
  61. plugins: defaultPlugins,
  62. // if prod, add externals
  63. // externals: isProd ? assetsCDN.externals : {}
  64. },
  65. filenameHashing: false, //去掉文件名后的hash
  66. chainWebpack: (config) => {
  67. config.resolve.alias.set("@$", resolve("src")).set("jq", resolve("public/jq"));
  68. console.log("NODE_ENV", process.env.NODE_ENV);
  69. if (process.env.NODE_ENV == "plglib") {
  70. /**用于联调测试组件库的开发模式 */
  71. const plglibPath = process.env.PLGLIB_PATH;
  72. console.log("PLGLIB_PATH", process.env.PLGLIB_PATH);
  73. config.resolve.alias.set("plglib", resolve("_plglib")).set("@plglib", plglibPath + "/packages");
  74. }
  75. const svgRule = config.module.rule("svg");
  76. svgRule.uses.clear();
  77. svgRule
  78. .oneOf("inline")
  79. .resourceQuery(/inline/)
  80. .use("vue-svg-icon-loader")
  81. .loader("vue-svg-icon-loader")
  82. .end()
  83. .end()
  84. .oneOf("external")
  85. .use("file-loader")
  86. .loader("file-loader")
  87. .options({
  88. name: "assets/[name].[hash:8].[ext]",
  89. });
  90. // if prod is on
  91. // assets require on cdn
  92. if (isProd) {
  93. config.plugin("html").tap((args) => {
  94. // args[0].cdn = assetsCDN
  95. return args;
  96. });
  97. }
  98. config.plugins.delete("prefetch");
  99. // /js/views-enterprise-img-enterprise-112-png.js
  100. // 去除生产环境下的 console
  101. if (isProd) {
  102. config.optimization.minimizer("terser").tap((options) => {
  103. options[0].terserOptions.compress.drop_console = true;
  104. return options;
  105. });
  106. }
  107. },
  108. css: {
  109. loaderOptions: {
  110. less: {
  111. modifyVars: {
  112. // less vars,customize ant design theme
  113. // 'primary-color': '#F5222D',
  114. // 'link-color': '#F5222D',
  115. "border-radius-base": "2px",
  116. ...theme,
  117. },
  118. // DO NOT REMOVE THIS LINE
  119. javascriptEnabled: true,
  120. },
  121. },
  122. },
  123. devServer: {
  124. // development server port 8000
  125. port: 8000,
  126. // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
  127. // proxy: {
  128. // '/api': {
  129. // target: 'https://mock.ihx.me/mock/5baf3052f7da7e07e04a5116/antd-pro',
  130. // ws: false,
  131. // changeOrigin: true
  132. // }
  133. // }
  134. proxy: {
  135. "^/api": {
  136. // 通过配置来启动,有配置的使用配置,没有配置默认公司网关
  137. // target: 'http://192.168.1.212:7002', // 公司测试 conba
  138. // target: 'http://116.54.19.104:7002', // 昆中药 conba
  139. // target: 'http://192.168.1.88:30127', // 康恩贝 conba
  140. // target: "http://10.30.67.19:7002", // 思源
  141. // target: 'http://192.168.1.88:30262', // 思源医疗测试环境
  142. // target: "http://192.168.1.200:7002", // 鹰江开发环境
  143. target: "http://wms-qingniu.upcloud.plg.com", //青牛开发环境
  144. // target: "http://192.168.1.88:31533", //青牛测试环境
  145. // 192.168.1.37:27200/home
  146. pathRewrite: {
  147. "^/api": "/api",
  148. },
  149. },
  150. "^/qneis_": {
  151. target: "http://192.168.41.208:10019",
  152. pathRewrite: {
  153. "^/qneis_": "",
  154. },
  155. },
  156. "/localw": {
  157. target: "http://127.0.0.1:6060",
  158. changeOrigin: true,
  159. ws: false,
  160. pathRewrite: {
  161. "^/localw": "",
  162. },
  163. },
  164. },
  165. },
  166. // disable source map in production
  167. productionSourceMap: false,
  168. lintOnSave: false,
  169. // babel-loader no-ignore node_modules/*
  170. transpileDependencies: [],
  171. /* 设计器运行时编译需要 */
  172. runtimeCompiler: true,
  173. };
  174. // preview.pro.loacg.com only do not use in your production;
  175. if (process.env.VUE_APP_PREVIEW === "true") {
  176. console.log("VUE_APP_PREVIEW", true);
  177. // add `ThemeColorReplacer` plugin to webpack plugins
  178. // vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
  179. }
  180. //vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
  181. module.exports = vueConfig;