vue.config.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. 'use strict'
  2. const path = require('path')
  3. // 导入compression-webpack-plugin 压缩JS大小
  4. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  5. // 定义压缩文件类型 压缩JS大小
  6. const productionGzipExtensions = ['js', 'css']
  7. function resolve(dir) {
  8. return path.join(__dirname, dir)
  9. }
  10. const name = process.env.VUE_APP_TITLE || '云联私域管理系统' // 网页标题
  11. const port = process.env.port || process.env.npm_config_port || 83 // 端口
  12. // vue.config.js 配置说明
  13. //官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions
  14. // 这里只列一部分,具体配置参考文档
  15. module.exports = {
  16. // 部署生产环境和开发环境下的URL。
  17. // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上
  18. // 例如 https://www.test.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.test.vip/admin/,则设置 baseUrl 为 /admin/。
  19. publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
  20. // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist)
  21. outputDir: 'dist',
  22. // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)
  23. assetsDir: 'static',
  24. // 是否开启eslint保存检测,有效值:ture | false | 'error'
  25. lintOnSave: process.env.NODE_ENV === 'development',
  26. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  27. productionSourceMap: false,
  28. // webpack-dev-server 相关配置
  29. devServer: {
  30. host: '0.0.0.0',
  31. port: port,
  32. open: true,
  33. proxy: {
  34. // 为 watch 模块单独设置的代理
  35. '/watch-api': {
  36. target: 'http://localhost:8114',
  37. changeOrigin: true,
  38. pathRewrite: {
  39. '^/watch-api': ''
  40. }
  41. },
  42. // 以下路径前缀代理到 fs-admin(8004) - 平台管理端
  43. // saasui前端API中这些路径只在fs-admin有Controller
  44. // 注:/crm/customerUser 已移入fs-company,不再需要独立代理至fs-admin
  45. [process.env.VUE_APP_BASE_API + '/admin']: {
  46. target: 'http://localhost:8004',
  47. changeOrigin: true,
  48. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  49. },
  50. [process.env.VUE_APP_BASE_API + '/api']: {
  51. target: 'http://localhost:8004',
  52. changeOrigin: true,
  53. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  54. },
  55. [process.env.VUE_APP_BASE_API + '/baiduStatistics']: {
  56. target: 'http://localhost:8004',
  57. changeOrigin: true,
  58. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  59. },
  60. [process.env.VUE_APP_BASE_API + '/bd']: {
  61. target: 'http://localhost:8004',
  62. changeOrigin: true,
  63. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  64. },
  65. [process.env.VUE_APP_BASE_API + '/doctorChat']: {
  66. target: 'http://localhost:8004',
  67. changeOrigin: true,
  68. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  69. },
  70. [process.env.VUE_APP_BASE_API + '/easyCall']: {
  71. target: 'http://localhost:8004',
  72. changeOrigin: true,
  73. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  74. },
  75. [process.env.VUE_APP_BASE_API + '/fs']: {
  76. target: 'http://localhost:8004',
  77. changeOrigin: true,
  78. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  79. },
  80. [process.env.VUE_APP_BASE_API + '/proxy']: {
  81. target: 'http://localhost:8004',
  82. changeOrigin: true,
  83. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  84. },
  85. [process.env.VUE_APP_BASE_API + '/sop']: {
  86. target: 'http://localhost:8004',
  87. changeOrigin: true,
  88. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  89. },
  90. [process.env.VUE_APP_BASE_API + '/tenant']: {
  91. target: 'http://localhost:8004',
  92. changeOrigin: true,
  93. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  94. },
  95. [process.env.VUE_APP_BASE_API + '/third']: {
  96. target: 'http://localhost:8004',
  97. changeOrigin: true,
  98. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  99. },
  100. [process.env.VUE_APP_BASE_API + '/tool']: {
  101. target: 'http://localhost:8004',
  102. changeOrigin: true,
  103. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  104. },
  105. // detail: https://cli.vuejs.org/config/#devserver-proxy
  106. // 默认所有其他请求代理到 fs-company(8006) - 租户服务端
  107. [process.env.VUE_APP_BASE_API]: {
  108. target: `http://localhost:8006`,
  109. changeOrigin: true,
  110. pathRewrite: {
  111. ['^' + process.env.VUE_APP_BASE_API]: ''
  112. }
  113. }
  114. },
  115. disableHostCheck: true
  116. },
  117. configureWebpack: config => { //压缩JS大小
  118. // 第一部分配置(对象形式转函数操作)
  119. config.name = name;
  120. config.resolve = {
  121. ...config.resolve,
  122. alias: {
  123. ...(config.resolve.alias || {}),
  124. '@': resolve('src'),
  125. 'styles': resolve("src/components/LemonUI/styles")
  126. }
  127. };
  128. if (process.env.NODE_ENV === 'production') {
  129. config.plugins.push(
  130. new CompressionWebpackPlugin({
  131. // filename: '[path].gz[query]',
  132. // algorithm: 'gzip',
  133. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  134. threshold: 5120,
  135. minRatio: 0.4
  136. })
  137. )
  138. } else {
  139. // 开发环境
  140. }
  141. },
  142. chainWebpack(config) {
  143. config.plugins.delete('preload') // TODO: need test
  144. config.plugins.delete('prefetch') // TODO: need test
  145. // set svg-sprite-loader
  146. config.module
  147. .rule('svg')
  148. .exclude.add(resolve('src/assets/icons'))
  149. .end()
  150. config.module
  151. .rule('icons')
  152. .test(/\.svg$/)
  153. .include.add(resolve('src/assets/icons'))
  154. .end()
  155. .use('svg-sprite-loader')
  156. .loader('svg-sprite-loader')
  157. .options({
  158. symbolId: 'icon-[name]'
  159. })
  160. .end()
  161. config
  162. .when(process.env.NODE_ENV !== 'development',
  163. config => {
  164. config
  165. .plugin('ScriptExtHtmlWebpackPlugin')
  166. .after('html')
  167. .use('script-ext-html-webpack-plugin', [{
  168. // `runtime` must same as runtimeChunk name. default is `runtime`
  169. inline: /runtime\..*\.js$/
  170. }])
  171. .end()
  172. config
  173. .optimization.splitChunks({
  174. chunks: 'all',
  175. cacheGroups: {
  176. libs: {
  177. name: 'chunk-libs',
  178. test: /[\\/]node_modules[\\/]/,
  179. priority: 10,
  180. chunks: 'initial' // only package third parties that are initially dependent
  181. },
  182. elementUI: {
  183. name: 'chunk-elementUI', // split elementUI into a single package
  184. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  185. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  186. },
  187. commons: {
  188. name: 'chunk-commons',
  189. test: resolve('src/components'), // can customize your rules
  190. minChunks: 3, // minimum common number
  191. priority: 5,
  192. reuseExistingChunk: true
  193. }
  194. }
  195. })
  196. config.optimization.runtimeChunk('single'),
  197. {
  198. from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
  199. to: './' //到根目录下
  200. }
  201. }
  202. )
  203. }
  204. }