vue.config.js 5.2 KB

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