vue.config.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 || 'vue Admin Template'; // page title
  8. // If your port is set to 80,
  9. // use administrator privileges to execute the command line.
  10. // For example, Mac: sudo npm run
  11. // You can change the port by the following methods:
  12. // port = 9528 npm run dev OR npm run dev --port = 9528
  13. // const port = 8083; // dev port
  14. const port = 8081; // dev port
  15. // const saveJSON = process.env.VUE_APP_BASE_API === 'development' &&
  16. // process.env.VUE_APP_BASE_API === 'true'
  17. const context = process.env.VUE_APP_BASE_API
  18. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  19. module.exports = {
  20. /**
  21. * You will need to set publicPath if you plan to deploy your site under a sub path,
  22. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  23. * then publicPath should be set to "/bar/".
  24. * In most cases please use '/' !!!
  25. * Detail: https://cli.vuejs.org/config/#publicpath
  26. */
  27. publicPath: './',
  28. outputDir: 'dist',
  29. assetsDir: 'static',
  30. lintOnSave: false,
  31. productionSourceMap: false,
  32. devServer: {
  33. open: true,
  34. overlay: {
  35. warnings: false,
  36. errors: true,
  37. },
  38. proxy: {
  39. '/api': {
  40. // 医院开发
  41. // target: ' http://10.32.45.11:8081/',
  42. // 外网开发
  43. target: 'http://182.44.10.206:8081',
  44. ws: true,
  45. changeOrigin: true, //是否跨域
  46. },
  47. '/bazb': {
  48. // 医院开发
  49. // target: ' http://10.32.45.11:8081/',
  50. // 外网开发
  51. target: 'http://182.44.10.206:8081',
  52. ws: true,
  53. changeOrigin: true, //是否跨域
  54. },
  55. '/bass': {
  56. // 医院开发
  57. // target: ' http://10.32.45.11:8081/',
  58. // 外网开发
  59. target: 'http://182.44.10.206:8081',
  60. ws: true,
  61. changeOrigin: true, //是否跨域
  62. },
  63. '/yxbl': {
  64. // 医院开发
  65. // target: ' http://10.32.45.11:8081/',
  66. // 外网开发
  67. target: 'http://182.44.10.206:8081',
  68. ws: true,
  69. changeOrigin: true, //是否跨域
  70. },
  71. //大模型接口
  72. '/api/predict/': {
  73. target: 'http://10.32.45.51:8000',
  74. ws: true,
  75. changeOrigin: true, //是否跨域
  76. }
  77. },
  78. port: port,
  79. before: require('./mock/mock-server.js'),
  80. },
  81. configureWebpack: {
  82. // provide the app's title in webpack's name field, so that
  83. // it can be accessed in index.html to inject the correct title.
  84. name: name,
  85. resolve: {
  86. alias: {
  87. '@': resolve('src'),
  88. },
  89. },
  90. },
  91. chainWebpack(config) {
  92. // it can improve the speed of the first screen, it is recommended to turn on preload
  93. config.plugin('preload').tap(() => [
  94. {
  95. rel: 'preload',
  96. // to ignore runtime.js
  97. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  98. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  99. include: 'initial',
  100. },
  101. ]);
  102. // when there are many pages, it will cause too many meaningless requests
  103. config.plugins.delete('prefetch');
  104. // set svg-sprite-loader
  105. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  106. config.module
  107. .rule('icons')
  108. .test(/\.svg$/)
  109. .include.add(resolve('src/icons'))
  110. .end()
  111. .use('svg-sprite-loader')
  112. .loader('svg-sprite-loader')
  113. .options({
  114. symbolId: 'icon-[name]',
  115. })
  116. .end();
  117. config.when(process.env.NODE_ENV !== 'development', config => {
  118. config
  119. .plugin('ScriptExtHtmlWebpackPlugin')
  120. .after('html')
  121. .use('script-ext-html-webpack-plugin', [
  122. {
  123. // `runtime` must same as runtimeChunk name. default is `runtime`
  124. inline: /runtime\..*\.js$/,
  125. },
  126. ])
  127. .end();
  128. config.optimization.splitChunks({
  129. chunks: 'all',
  130. cacheGroups: {
  131. libs: {
  132. name: 'chunk-libs',
  133. test: /[\\/]node_modules[\\/]/,
  134. priority: 10,
  135. chunks: 'initial', // only package third parties that are initially dependent
  136. },
  137. elementUI: {
  138. name: 'chunk-elementUI', // split elementUI into a single package
  139. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  140. test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
  141. },
  142. commons: {
  143. name: 'chunk-commons',
  144. test: resolve('src/components'), // can customize your rules
  145. minChunks: 3, // minimum common number
  146. priority: 5,
  147. reuseExistingChunk: true,
  148. },
  149. },
  150. });
  151. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  152. config.optimization.runtimeChunk('single');
  153. });
  154. },
  155. };