vue.config.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. 'use strict'
  2. const path = require('path')
  3. const fs = require('fs')
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. // If your port is set to 80,
  8. // use administrator privileges to execute the command line.
  9. // For example, Mac: sudo npm run
  10. // You can change the port by the following methods:
  11. // port = 9528 npm run dev OR npm run dev --port = 9528
  12. const port = process.env.port || process.env.npm_config_port || 9528 // dev port
  13. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  14. module.exports = {
  15. /**
  16. * You will need to set publicPath if you plan to deploy your site under a sub path,
  17. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  18. * then publicPath should be set to "/bar/".
  19. * In most cases please use '/' !!!
  20. * Detail: https://cli.vuejs.org/config/#publicpath
  21. */
  22. publicPath: './',
  23. outputDir: 'dist',
  24. assetsDir: 'static',
  25. lintOnSave: process.env.NODE_ENV === 'development',
  26. productionSourceMap: false,
  27. devServer: {
  28. port: port,
  29. open: true,
  30. overlay: {
  31. warnings: false,
  32. errors: true
  33. }
  34. },
  35. configureWebpack: {
  36. // provide the app's title in webpack's name field, so that
  37. // it can be accessed in index.html to inject the correct title.
  38. resolve: {
  39. alias: {
  40. '@': resolve('src')
  41. }
  42. },
  43. devServer: {
  44. proxy: {
  45. // "^/user": {target: "http://192.168.58.137:10086"},
  46. "^/(user|goods|goodsTypes|order|orderItem|rooms|room)/": { target: "http://192.168.43.46:10086" },
  47. "^/.*": { target: "http://116.63.32.160:8085" },
  48. },
  49. }
  50. },
  51. chainWebpack(config) {
  52. // it can improve the speed of the first screen, it is recommended to turn on preload
  53. config.plugin('preload').tap(() => [
  54. {
  55. rel: 'preload',
  56. // to ignore runtime.js
  57. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  58. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  59. include: 'initial'
  60. }
  61. ])
  62. // when there are many pages, it will cause too many meaningless requests
  63. config.plugins.delete('prefetch')
  64. // set svg-sprite-loader
  65. config.module
  66. .rule('svg')
  67. .exclude.add(resolve('src/icons'))
  68. .end()
  69. config.module
  70. .rule('icons')
  71. .test(/\.svg$/)
  72. .include.add(resolve('src/icons'))
  73. .end()
  74. .use('svg-sprite-loader')
  75. .loader('svg-sprite-loader')
  76. .end()
  77. config
  78. .when(process.env.ANALYZER == 'true', config => {
  79. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  80. config.plugin('webpack-bundle-analyzer').use(BundleAnalyzerPlugin).tap(() => [
  81. {
  82. analyzerPort: "auto"
  83. }
  84. ])
  85. })
  86. config
  87. .when(process.env.NODE_ENV !== 'development',
  88. config => {
  89. config
  90. .plugin('ScriptExtHtmlWebpackPlugin')
  91. .after('html')
  92. .use('script-ext-html-webpack-plugin', [{
  93. // `runtime` must same as runtimeChunk name. default is `runtime`
  94. inline: /runtime\..*\.js$/
  95. }])
  96. .end()
  97. config
  98. .optimization.splitChunks({
  99. chunks: 'all',
  100. cacheGroups: {
  101. libs: {
  102. name: 'libs',
  103. priority: 50,
  104. chunks: 'initial',
  105. },
  106. elementUI: {
  107. name: 'elementUI', // split elementUI into a single package
  108. priority: 40,
  109. test: /[\\/]node_modules[\\/]_?element-ui(.*)/,
  110. },
  111. avue: {
  112. name: 'avue', // split avue into a single package
  113. priority: 41,
  114. test: /[\\/]node_modules[\\/]@smallwei(.*)/,
  115. reuseExistingChunk: true
  116. },
  117. utils: {
  118. name: 'utils',
  119. test: /([\\/]src[\\/]utils)|lodash|axios|crypto-js/,
  120. priority: 30,
  121. },
  122. styles: {
  123. name: 'styles', // pack all remaining style files
  124. test: /\.(css|scss)$/,
  125. priority: 45,
  126. reuseExistingChunk: true
  127. },
  128. }
  129. })
  130. }
  131. )
  132. }
  133. }