vue.config.js 4.6 KB

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