vue.config.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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.65: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.152:18081/oms`,
  83. // changeOrigin: true,
  84. // // logLevel: 'debug', //打印日志
  85. // pathRewrite: {
  86. // ['^' + process.env.VUE_APP_OMS_API]: ''
  87. // }
  88. // },
  89. }
  90. },
  91. // webpack配置
  92. configureWebpack: {
  93. name: name,
  94. resolve: {
  95. alias: {
  96. "@": resolve("src")
  97. }
  98. }
  99. },
  100. chainWebpack(config) {
  101. // 删除预加载
  102. config.plugins.delete("preload"); // TODO: need test
  103. config.plugins.delete("prefetch"); // TODO: need test
  104. // set svg-sprite-loader
  105. config.module
  106. .rule("svg")
  107. .exclude.add(resolve("src/icons"))
  108. .end();
  109. config.module
  110. .rule("icons")
  111. .test(/\.svg$/)
  112. .include.add(resolve("src/icons"))
  113. .end()
  114. .use("svg-sprite-loader")
  115. .loader("svg-sprite-loader")
  116. .options({
  117. symbolId: "icon-[name]"
  118. })
  119. .end();
  120. // set preserveWhitespace
  121. config.module
  122. .rule("vue")
  123. .use("vue-loader")
  124. .loader("vue-loader")
  125. .tap(options => {
  126. options.compilerOptions.preserveWhitespace = true;
  127. return options;
  128. })
  129. .end();
  130. config
  131. // https://webpack.js.org/configuration/devtool/#development
  132. .when(process.env.NODE_ENV === "development", config =>
  133. config.devtool("cheap-source-map")
  134. );
  135. config.when(process.env.NODE_ENV !== "development", config => {
  136. //非开发环境
  137. config
  138. .plugin("ScriptExtHtmlWebpackPlugin")
  139. .after("html")
  140. .use("script-ext-html-webpack-plugin", [
  141. {
  142. // `runtime` must same as runtimeChunk name. default is `runtime`
  143. inline: /runtime\..*\.js$/
  144. }
  145. ])
  146. .end();
  147. // 分割代码
  148. config.optimization.splitChunks({
  149. chunks: "all",
  150. cacheGroups: {
  151. libs: {
  152. name: "chunk-libs",
  153. test: /[\\/]node_modules[\\/]/,
  154. priority: 10,
  155. chunks: "initial" // only package third parties that are initially dependent
  156. },
  157. elementUI: {
  158. name: "chunk-elementUI", // split elementUI into a single package
  159. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  160. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  161. },
  162. commons: {
  163. name: "chunk-commons",
  164. test: resolve("src/components"), // can customize your rules
  165. minChunks: 3, // minimum common number
  166. priority: 5,
  167. reuseExistingChunk: false
  168. }
  169. }
  170. });
  171. config.optimization.runtimeChunk("single");
  172. });
  173. }
  174. };