vue.config.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 Element Admin' // 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 method:
  12. // port = 9527 npm run dev OR npm run dev --port = 9527
  13. const port = process.env.port || process.env.npm_config_port || 9527 // dev port
  14. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  15. module.exports = {
  16. /**
  17. * You will need to set publicPath if you plan to deploy your site under a sub path,
  18. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  19. * then publicPath should be set to "/bar/".
  20. * In most cases please use '/' !!!
  21. * Detail: https://cli.vuejs.org/config/#publicpath
  22. */
  23. publicPath: '/',
  24. outputDir: 'dist',
  25. assetsDir: 'static',
  26. // lintOnSave: process.env.NODE_ENV === 'development',
  27. // 取消 ESLint 校验
  28. lintOnSave:false,
  29. productionSourceMap: false,
  30. devServer: {
  31. proxy: { //配置跨域
  32. '/': {
  33. target: 'http://101.36.160.140:21021', //这里后台的地址模拟的;应该填写你们真实的后台接口
  34. // target:'http://172.16.0.02:9601',
  35. changOrigin: true, //允许跨域
  36. pathRewrite: {
  37. /* 重写路径,当我们在浏览器中看到请求的地址为:http://localhost:8080/api/core/getData/userInfo 时
  38. 实际上访问的地址是:http://121.121.67.254:8185/core/getData/userInfo,因为重写了 /api
  39. */
  40. '^/': ''
  41. }
  42. },
  43. '/webs': {
  44. target: 'http://139.159.183.224:19999', //这里后台的地址模拟的;应该填写你们真实的后台接口
  45. // target:'http://172.16.0.02:9601',
  46. changOrigin: true, //允许跨域
  47. pathRewrite: {
  48. /* 重写路径,当我们在浏览器中看到请求的地址为:http://localhost:8080/api/core/getData/userInfo 时
  49. 实际上访问的地址是:http://121.121.67.254:8185/core/getData/userInfo,因为重写了 /api
  50. */
  51. '^/webs': ''
  52. }
  53. },
  54. },
  55. port: port,
  56. open: true,
  57. overlay: {
  58. warnings: false,
  59. errors: true
  60. },
  61. //before: require('./mock/mock-server.js') //注释,不然会先走mock,然后再走本地服务不,被mock拦截了
  62. },
  63. configureWebpack: {
  64. // provide the app's title in webpack's name field, so that
  65. // it can be accessed in index.html to inject the correct title.
  66. name: name,
  67. resolve: {
  68. alias: {
  69. '@': resolve('src')
  70. }
  71. }
  72. },
  73. chainWebpack(config) {
  74. // it can improve the speed of the first screen, it is recommended to turn on preload
  75. // it can improve the speed of the first screen, it is recommended to turn on preload
  76. config.plugin('preload').tap(() => [
  77. {
  78. rel: 'preload',
  79. // to ignore runtime.js
  80. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  81. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  82. include: 'initial'
  83. }
  84. ])
  85. // when there are many pages, it will cause too many meaningless requests
  86. config.plugins.delete('prefetch')
  87. // set svg-sprite-loader
  88. config.module
  89. .rule('svg')
  90. .exclude.add(resolve('src/icons'))
  91. .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
  104. .when(process.env.NODE_ENV !== 'development',
  105. config => {
  106. config
  107. .plugin('ScriptExtHtmlWebpackPlugin')
  108. .after('html')
  109. .use('script-ext-html-webpack-plugin', [{
  110. // `runtime` must same as runtimeChunk name. default is `runtime`
  111. inline: /runtime\..*\.js$/
  112. }])
  113. .end()
  114. config
  115. .optimization.splitChunks({
  116. chunks: 'all',
  117. cacheGroups: {
  118. libs: {
  119. name: 'chunk-libs',
  120. test: /[\\/]node_modules[\\/]/,
  121. priority: 10,
  122. chunks: 'initial' // only package third parties that are initially dependent
  123. },
  124. elementUI: {
  125. name: 'chunk-elementUI', // split elementUI into a single package
  126. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  127. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  128. },
  129. commons: {
  130. name: 'chunk-commons',
  131. test: resolve('src/components'), // can customize your rules
  132. minChunks: 3, // minimum common number
  133. priority: 5,
  134. reuseExistingChunk: true
  135. }
  136. }
  137. })
  138. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  139. config.optimization.runtimeChunk('single')
  140. }
  141. )
  142. }
  143. }