vue.config.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. const webpack = require('webpack');
  5. function resolve(dir) {
  6. return path.join(__dirname, dir)
  7. }
  8. const name = defaultSettings.title || 'vue Element Admin' // page title
  9. // If your port is set to 80,
  10. // use administrator privileges to execute the command line.
  11. // For example, Mac: sudo npm run
  12. // You can change the port by the following method:
  13. // port = 9527 npm run dev OR npm run dev --port = 9527
  14. const port = process.env.port || process.env.npm_config_port || 9527 // dev port
  15. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  16. module.exports = {
  17. /**
  18. * You will need to set publicPath if you plan to deploy your site under a sub path,
  19. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  20. * then publicPath should be set to "/bar/".
  21. * In most cases please use '/' !!!
  22. * Detail: https://cli.vuejs.org/config/#publicpath
  23. */
  24. publicPath: '/',
  25. outputDir: 'dist',
  26. assetsDir: 'static',
  27. //lintOnSave: process.env.NODE_ENV === 'development',
  28. lintOnSave: false,
  29. productionSourceMap: false,
  30. devServer: {
  31. port: port,
  32. open: true,
  33. overlay: {
  34. warnings: false,
  35. errors: true
  36. },
  37. //before: require('./mock/mock-server.js')
  38. // proxy: {
  39. // '/authority/getRecursionMenu': {
  40. // target: 'http://192.168.1.201:9501',
  41. // changeOrigin: true,
  42. // logLevel: 'debug',
  43. // onProxyReq: (proxyReq) => {
  44. // proxyReq.setHeader('Origin', 'http://192.168.1.201:8099');
  45. // console.log('Origin header set to http://192.168.1.201:8099');
  46. // },
  47. // pathRewrite: { '^http://192.168.1.201:9501': '' } // 重写完整路径
  48. // }
  49. // }
  50. //本地ai
  51. proxy: {
  52. //代理/ai的请求到我本地
  53. '/ai': {
  54. target: 'http://127.0.0.1:5000',
  55. changeOrigin: true,
  56. // 不需要 pathRewrite,保持 /ai 路径
  57. logLevel: 'debug' // 可选,查看代理日志
  58. }
  59. // 其他请求不会走代理,保持原有行为
  60. }
  61. },
  62. css: {
  63. loaderOptions: {
  64. sass: {
  65. sassOptions: {
  66. outputStyle: 'expanded',
  67. quietDeps: true, // 忽略第三方库的警告
  68. }
  69. }
  70. }
  71. },
  72. configureWebpack: {
  73. // provide the app's title in webpack's name field, so that
  74. // it can be accessed in index.html to inject the correct title.
  75. name: name,
  76. resolve: {
  77. alias: {
  78. '@': resolve('src')
  79. }
  80. }
  81. },
  82. chainWebpack(config) {
  83. // it can improve the speed of the first screen, it is recommended to turn on preload
  84. // it can improve the speed of the first screen, it is recommended to turn on preload
  85. config.plugin('preload').tap(() => [
  86. {
  87. rel: 'preload',
  88. // to ignore runtime.js
  89. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  90. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  91. include: 'initial'
  92. }
  93. ])
  94. // when there are many pages, it will cause too many meaningless requests
  95. config.plugins.delete('prefetch')
  96. // set svg-sprite-loader
  97. config.module
  98. .rule('svg')
  99. .exclude.add(resolve('src/icons'))
  100. .end()
  101. config.module
  102. .rule('icons')
  103. .test(/\.svg$/)
  104. .include.add(resolve('src/icons'))
  105. .end()
  106. .use('svg-sprite-loader')
  107. .loader('svg-sprite-loader')
  108. .options({
  109. symbolId: 'icon-[name]'
  110. })
  111. .end()
  112. config
  113. .when(process.env.NODE_ENV !== 'development',
  114. config => {
  115. config
  116. .plugin('ScriptExtHtmlWebpackPlugin')
  117. .after('html')
  118. .use('script-ext-html-webpack-plugin', [{
  119. // `runtime` must same as runtimeChunk name. default is `runtime`
  120. inline: /runtime\..*\.js$/
  121. }])
  122. .end()
  123. config
  124. .optimization.splitChunks({
  125. chunks: 'all',
  126. cacheGroups: {
  127. libs: {
  128. name: 'chunk-libs',
  129. test: /[\\/]node_modules[\\/]/,
  130. priority: 10,
  131. chunks: 'initial' // only package third parties that are initially dependent
  132. },
  133. elementUI: {
  134. name: 'chunk-elementUI', // split elementUI into a single package
  135. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  136. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  137. },
  138. commons: {
  139. name: 'chunk-commons',
  140. test: resolve('src/components'), // can customize your rules
  141. minChunks: 3, // minimum common number
  142. priority: 5,
  143. reuseExistingChunk: true
  144. }
  145. }
  146. })
  147. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  148. config.optimization.runtimeChunk('single')
  149. }
  150. )
  151. }
  152. }