vue.config.js 4.5 KB

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