vue.config.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. port: port,
  73. before: require('./mock/mock-server.js'),
  74. },
  75. configureWebpack: {
  76. // provide the app's title in webpack's name field, so that
  77. // it can be accessed in index.html to inject the correct title.
  78. name: name,
  79. resolve: {
  80. alias: {
  81. '@': resolve('src'),
  82. },
  83. },
  84. },
  85. chainWebpack(config) {
  86. // it can improve the speed of the first screen, it is recommended to turn on preload
  87. config.plugin('preload').tap(() => [
  88. {
  89. rel: 'preload',
  90. // to ignore runtime.js
  91. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  92. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  93. include: 'initial',
  94. },
  95. ]);
  96. // when there are many pages, it will cause too many meaningless requests
  97. config.plugins.delete('prefetch');
  98. // set svg-sprite-loader
  99. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  100. config.module
  101. .rule('icons')
  102. .test(/\.svg$/)
  103. .include.add(resolve('src/icons'))
  104. .end()
  105. .use('svg-sprite-loader')
  106. .loader('svg-sprite-loader')
  107. .options({
  108. symbolId: 'icon-[name]',
  109. })
  110. .end();
  111. config.when(process.env.NODE_ENV !== 'development', config => {
  112. config
  113. .plugin('ScriptExtHtmlWebpackPlugin')
  114. .after('html')
  115. .use('script-ext-html-webpack-plugin', [
  116. {
  117. // `runtime` must same as runtimeChunk name. default is `runtime`
  118. inline: /runtime\..*\.js$/,
  119. },
  120. ])
  121. .end();
  122. config.optimization.splitChunks({
  123. chunks: 'all',
  124. cacheGroups: {
  125. libs: {
  126. name: 'chunk-libs',
  127. test: /[\\/]node_modules[\\/]/,
  128. priority: 10,
  129. chunks: 'initial', // only package third parties that are initially dependent
  130. },
  131. elementUI: {
  132. name: 'chunk-elementUI', // split elementUI into a single package
  133. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  134. test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
  135. },
  136. commons: {
  137. name: 'chunk-commons',
  138. test: resolve('src/components'), // can customize your rules
  139. minChunks: 3, // minimum common number
  140. priority: 5,
  141. reuseExistingChunk: true,
  142. },
  143. },
  144. });
  145. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  146. config.optimization.runtimeChunk('single');
  147. });
  148. },
  149. };