vue.config.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 模块单独设置的代理(fs-watch微服务,独立部署)
  35. '/watch-api': {
  36. target: 'http://localhost:8114',
  37. changeOrigin: true,
  38. pathRewrite: {
  39. '^/watch-api': ''
  40. }
  41. },
  42. // 向量知识库相关接口 → fs-ai-api (9009)
  43. '/prod-api/qdrant': {
  44. target: 'http://localhost:9009',
  45. changeOrigin: true,
  46. pathRewrite: { '^/prod-api': '' }
  47. },
  48. // AI/Embedding 相关接口 → fs-ai-api (9009)
  49. '/prod-api/ai/': {
  50. target: 'http://localhost:9009',
  51. changeOrigin: true,
  52. pathRewrite: { '^/prod-api': '' }
  53. },
  54. // detail: https://cli.vuejs.org/config/#devserver-proxy
  55. // 默认所有请求代理到 fs-saas(8006) - 租户服务端
  56. // 注意:fs-saas已依赖fs-saasadmin,所有@Profile({"admin","company"})的Controller都可用
  57. // 原先代理到8004的12条路径(/admin,/api,/baiduStatistics,/bd,/doctorChat,/easyCall,/fs,/proxy,/sop,/tenant,/third,/tool)
  58. // 已全部在fs-saas(8006)上可用,无需跨服务
  59. [process.env.VUE_APP_BASE_API]: {
  60. target: `http://localhost:8006`,
  61. changeOrigin: true,
  62. pathRewrite: {
  63. ['^' + process.env.VUE_APP_BASE_API]: ''
  64. }
  65. }
  66. },
  67. disableHostCheck: true
  68. },
  69. configureWebpack: config => { //压缩JS大小
  70. // 第一部分配置(对象形式转函数操作)
  71. config.name = name;
  72. config.resolve = {
  73. ...config.resolve,
  74. alias: {
  75. ...(config.resolve.alias || {}),
  76. '@': resolve('src'),
  77. 'styles': resolve("src/components/LemonUI/styles")
  78. }
  79. };
  80. if (process.env.NODE_ENV === 'production') {
  81. config.plugins.push(
  82. new CompressionWebpackPlugin({
  83. // filename: '[path].gz[query]',
  84. // algorithm: 'gzip',
  85. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  86. threshold: 5120,
  87. minRatio: 0.4
  88. })
  89. )
  90. } else {
  91. // 开发环境
  92. }
  93. },
  94. chainWebpack(config) {
  95. config.plugins.delete('preload') // TODO: need test
  96. config.plugins.delete('prefetch') // TODO: need test
  97. // set svg-sprite-loader
  98. config.module
  99. .rule('svg')
  100. .exclude.add(resolve('src/assets/icons'))
  101. .end()
  102. config.module
  103. .rule('icons')
  104. .test(/\.svg$/)
  105. .include.add(resolve('src/assets/icons'))
  106. .end()
  107. .use('svg-sprite-loader')
  108. .loader('svg-sprite-loader')
  109. .options({
  110. symbolId: 'icon-[name]'
  111. })
  112. .end()
  113. config
  114. .when(process.env.NODE_ENV !== 'development',
  115. config => {
  116. config
  117. .plugin('ScriptExtHtmlWebpackPlugin')
  118. .after('html')
  119. .use('script-ext-html-webpack-plugin', [{
  120. // `runtime` must same as runtimeChunk name. default is `runtime`
  121. inline: /runtime\..*\.js$/
  122. }])
  123. .end()
  124. config
  125. .optimization.splitChunks({
  126. chunks: 'all',
  127. cacheGroups: {
  128. libs: {
  129. name: 'chunk-libs',
  130. test: /[\\/]node_modules[\\/]/,
  131. priority: 10,
  132. chunks: 'initial' // only package third parties that are initially dependent
  133. },
  134. elementUI: {
  135. name: 'chunk-elementUI', // split elementUI into a single package
  136. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  137. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  138. },
  139. commons: {
  140. name: 'chunk-commons',
  141. test: resolve('src/components'), // can customize your rules
  142. minChunks: 3, // minimum common number
  143. priority: 5,
  144. reuseExistingChunk: true
  145. }
  146. }
  147. })
  148. config.optimization.runtimeChunk('single'),
  149. {
  150. from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
  151. to: './' //到根目录下
  152. }
  153. }
  154. )
  155. }
  156. }