vue.config.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. [process.env.VUE_APP_BASE_API + '/admin']: {
  45. target: 'http://localhost:8004',
  46. changeOrigin: true,
  47. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  48. },
  49. [process.env.VUE_APP_BASE_API + '/api']: {
  50. target: 'http://localhost:8004',
  51. changeOrigin: true,
  52. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  53. },
  54. [process.env.VUE_APP_BASE_API + '/baiduStatistics']: {
  55. target: 'http://localhost:8004',
  56. changeOrigin: true,
  57. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  58. },
  59. [process.env.VUE_APP_BASE_API + '/bd']: {
  60. target: 'http://localhost:8004',
  61. changeOrigin: true,
  62. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  63. },
  64. [process.env.VUE_APP_BASE_API + '/doctorChat']: {
  65. target: 'http://localhost:8004',
  66. changeOrigin: true,
  67. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  68. },
  69. [process.env.VUE_APP_BASE_API + '/easyCall']: {
  70. target: 'http://localhost:8004',
  71. changeOrigin: true,
  72. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  73. },
  74. [process.env.VUE_APP_BASE_API + '/fs']: {
  75. target: 'http://localhost:8004',
  76. changeOrigin: true,
  77. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  78. },
  79. [process.env.VUE_APP_BASE_API + '/proxy']: {
  80. target: 'http://localhost:8004',
  81. changeOrigin: true,
  82. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  83. },
  84. [process.env.VUE_APP_BASE_API + '/sop']: {
  85. target: 'http://localhost:8004',
  86. changeOrigin: true,
  87. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  88. },
  89. [process.env.VUE_APP_BASE_API + '/tenant']: {
  90. target: 'http://localhost:8004',
  91. changeOrigin: true,
  92. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  93. },
  94. [process.env.VUE_APP_BASE_API + '/third']: {
  95. target: 'http://localhost:8004',
  96. changeOrigin: true,
  97. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  98. },
  99. [process.env.VUE_APP_BASE_API + '/tool']: {
  100. target: 'http://localhost:8004',
  101. changeOrigin: true,
  102. pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
  103. },
  104. // detail: https://cli.vuejs.org/config/#devserver-proxy
  105. // 默认所有其他请求代理到 fs-company(8006) - 租户服务端
  106. [process.env.VUE_APP_BASE_API]: {
  107. target: `http://localhost:8006`,
  108. changeOrigin: true,
  109. pathRewrite: {
  110. ['^' + process.env.VUE_APP_BASE_API]: ''
  111. }
  112. }
  113. },
  114. disableHostCheck: true
  115. },
  116. configureWebpack: config => { //压缩JS大小
  117. // 第一部分配置(对象形式转函数操作)
  118. config.name = name;
  119. config.resolve = {
  120. ...config.resolve,
  121. alias: {
  122. ...(config.resolve.alias || {}),
  123. '@': resolve('src'),
  124. 'styles': resolve("src/components/LemonUI/styles")
  125. }
  126. };
  127. if (process.env.NODE_ENV === 'production') {
  128. config.plugins.push(
  129. new CompressionWebpackPlugin({
  130. // filename: '[path].gz[query]',
  131. // algorithm: 'gzip',
  132. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  133. threshold: 5120,
  134. minRatio: 0.4
  135. })
  136. )
  137. } else {
  138. // 开发环境
  139. }
  140. },
  141. chainWebpack(config) {
  142. config.plugins.delete('preload') // TODO: need test
  143. config.plugins.delete('prefetch') // TODO: need test
  144. // set svg-sprite-loader
  145. config.module
  146. .rule('svg')
  147. .exclude.add(resolve('src/assets/icons'))
  148. .end()
  149. config.module
  150. .rule('icons')
  151. .test(/\.svg$/)
  152. .include.add(resolve('src/assets/icons'))
  153. .end()
  154. .use('svg-sprite-loader')
  155. .loader('svg-sprite-loader')
  156. .options({
  157. symbolId: 'icon-[name]'
  158. })
  159. .end()
  160. config
  161. .when(process.env.NODE_ENV !== 'development',
  162. config => {
  163. config
  164. .plugin('ScriptExtHtmlWebpackPlugin')
  165. .after('html')
  166. .use('script-ext-html-webpack-plugin', [{
  167. // `runtime` must same as runtimeChunk name. default is `runtime`
  168. inline: /runtime\..*\.js$/
  169. }])
  170. .end()
  171. config
  172. .optimization.splitChunks({
  173. chunks: 'all',
  174. cacheGroups: {
  175. libs: {
  176. name: 'chunk-libs',
  177. test: /[\\/]node_modules[\\/]/,
  178. priority: 10,
  179. chunks: 'initial' // only package third parties that are initially dependent
  180. },
  181. elementUI: {
  182. name: 'chunk-elementUI', // split elementUI into a single package
  183. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  184. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  185. },
  186. commons: {
  187. name: 'chunk-commons',
  188. test: resolve('src/components'), // can customize your rules
  189. minChunks: 3, // minimum common number
  190. priority: 5,
  191. reuseExistingChunk: true
  192. }
  193. }
  194. })
  195. config.optimization.runtimeChunk('single'),
  196. {
  197. from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
  198. to: './' //到根目录下
  199. }
  200. }
  201. )
  202. }
  203. }