vue.config.js 4.4 KB

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