vue.config.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. "use strict";
  2. const path = require("path");
  3. const defaultSettings = require("./src/settings.js");
  4. function resolve(dir) {
  5. return path.join(__dirname, dir);
  6. }
  7. const name = defaultSettings.title || "歌莉娅海外订单中心(FOMS)"; // 标题
  8. const port = process.env.port || process.env.npm_config_port || 9527; // 开发接口
  9. // 所有配置项描述 查看: https://cli.vuejs.org/config/
  10. module.exports = {
  11. publicPath: "./", // 基本路径
  12. outputDir: "dist", // 输出文件目录
  13. assetsDir: "static", // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。
  14. // 指定生成的 index.html 的输出路径 (相对于 outputDir)。也可以是一个绝对路径
  15. // indexPath: './',
  16. lintOnSave: process.env.NODE_ENV === "production", // lintOnSave: eslint-loader 是否在保存的时候检查
  17. productionSourceMap: false, // 生产环境是否生成 sourceMap 文件
  18. devServer: {
  19. port: port,
  20. // host: "swings.pim.com",
  21. // open: true,
  22. overlay: {
  23. warnings: false,
  24. errors: true
  25. },
  26. public: "0.0.0.0:9527", //可以实现热部署
  27. proxy: {
  28. // [process.env.VUE_APP_OAUTH_API]: {
  29. // target: `http://localhost:19090/sso`,
  30. // changeOrigin: true,
  31. // // logLevel: 'debug', //打印日志
  32. // pathRewrite: {
  33. // ['^' + process.env.VUE_APP_OAUTH_API]: ''
  34. // }
  35. // },
  36. // [process.env.VUE_APP_PIM_API]: {
  37. // target: `http://localhost:18080/pim`,
  38. // changeOrigin: true,
  39. // // logLevel: 'debug', //打印日志
  40. // pathRewrite: {
  41. // ['^' + process.env.VUE_APP_PIM_API]: ''
  42. // }
  43. // },
  44. // [process.env.VUE_APP_OMS_API]: {
  45. // target: `http://localhost:18081/oms`,
  46. // changeOrigin: true,
  47. // // logLevel: 'debug', //打印日志
  48. // pathRewrite: {
  49. // ['^' + process.env.VUE_APP_OMS_API]: ''
  50. // }
  51. // }
  52. // "/": {
  53. // target: "https://testfoms.gloria.com.cn",
  54. // changeOrigin: true
  55. // },
  56. //http://10.41.3.152:18081 http://10.41.3.65:19090
  57. [process.env.VUE_APP_OAUTH_API]: {
  58. target: `http://10.41.3.65:19090/sso`,
  59. changeOrigin: true,
  60. // logLevel: 'debug', //打印日志
  61. pathRewrite: {
  62. ['^' + process.env.VUE_APP_OAUTH_API]: ''
  63. }
  64. },
  65. [process.env.VUE_APP_PIM_API]: {
  66. target: `http://10.41.3.65:18081/pim`,
  67. changeOrigin: true,
  68. // logLevel: 'debug', //打印日志
  69. pathRewrite: {
  70. ['^' + process.env.VUE_APP_PIM_API]: ''
  71. }
  72. },
  73. [process.env.VUE_APP_OMS_API]: {
  74. target: `http://10.41.3.106:18081/oms`,
  75. changeOrigin: true,
  76. // logLevel: 'debug', //打印日志
  77. pathRewrite: {
  78. ['^' + process.env.VUE_APP_OMS_API]: ''
  79. }
  80. },
  81. // [process.env.VUE_APP_OMS_API]: {
  82. // target: `http://10.41.3.65:18081/oms`,
  83. // changeOrigin: true,
  84. // // logLevel: 'debug', //打印日志
  85. // pathRewrite: {
  86. // ['^' + process.env.VUE_APP_OMS_API]: ''
  87. // }
  88. // },
  89. // [process.env.VUE_APP_OMS_API]: { 廖望
  90. // target: `http://10.41.3.152:18081/oms`,
  91. // changeOrigin: true,
  92. // // logLevel: 'debug', //打印日志
  93. // pathRewrite: {
  94. // ['^' + process.env.VUE_APP_OMS_API]: ''
  95. // }
  96. // },
  97. }
  98. },
  99. // webpack配置
  100. configureWebpack: {
  101. name: name,
  102. resolve: {
  103. alias: {
  104. "@": resolve("src")
  105. }
  106. }
  107. },
  108. chainWebpack(config) {
  109. // 删除预加载
  110. config.plugins.delete("preload"); // TODO: need test
  111. config.plugins.delete("prefetch"); // TODO: need test
  112. // set svg-sprite-loader
  113. config.module
  114. .rule("svg")
  115. .exclude.add(resolve("src/icons"))
  116. .end();
  117. config.module
  118. .rule("icons")
  119. .test(/\.svg$/)
  120. .include.add(resolve("src/icons"))
  121. .end()
  122. .use("svg-sprite-loader")
  123. .loader("svg-sprite-loader")
  124. .options({
  125. symbolId: "icon-[name]"
  126. })
  127. .end();
  128. // set preserveWhitespace
  129. config.module
  130. .rule("vue")
  131. .use("vue-loader")
  132. .loader("vue-loader")
  133. .tap(options => {
  134. options.compilerOptions.preserveWhitespace = true;
  135. return options;
  136. })
  137. .end();
  138. config
  139. // https://webpack.js.org/configuration/devtool/#development
  140. .when(process.env.NODE_ENV === "development", config =>
  141. config.devtool("cheap-source-map")
  142. );
  143. config.when(process.env.NODE_ENV !== "development", config => {
  144. //非开发环境
  145. config
  146. .plugin("ScriptExtHtmlWebpackPlugin")
  147. .after("html")
  148. .use("script-ext-html-webpack-plugin", [
  149. {
  150. // `runtime` must same as runtimeChunk name. default is `runtime`
  151. inline: /runtime\..*\.js$/
  152. }
  153. ])
  154. .end();
  155. // 分割代码
  156. config.optimization.splitChunks({
  157. chunks: "all",
  158. cacheGroups: {
  159. libs: {
  160. name: "chunk-libs",
  161. test: /[\\/]node_modules[\\/]/,
  162. priority: 10,
  163. chunks: "initial" // only package third parties that are initially dependent
  164. },
  165. elementUI: {
  166. name: "chunk-elementUI", // split elementUI into a single package
  167. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  168. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  169. },
  170. commons: {
  171. name: "chunk-commons",
  172. test: resolve("src/components"), // can customize your rules
  173. minChunks: 3, // minimum common number
  174. priority: 5,
  175. reuseExistingChunk: false
  176. }
  177. }
  178. });
  179. config.optimization.runtimeChunk("single");
  180. });
  181. }
  182. };