vue.config.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. 'use strict'
  2. const path = require('path')
  3. const pkg = require('./package.json')
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. const name = pkg.name || 'vue-element-admin' // page title
  8. const port = 9528 // dev port
  9. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  10. module.exports = {
  11. /**
  12. * You will need to set publicPath if you plan to deploy your site under a sub path,
  13. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  14. * then publicPath should be set to "/bar/".
  15. * In most cases please use '/' !!!
  16. * Detail: https://cli.vuejs.org/config/#publicpath
  17. */
  18. publicPath: process.env.VUE_APP_CONTEXT,
  19. outputDir: 'dist',
  20. assetsDir: 'static',
  21. lintOnSave: process.env.NODE_ENV === 'development' ? 'error' : false,
  22. productionSourceMap: false,
  23. devServer: {
  24. port: port,
  25. open: false,
  26. overlay: {
  27. warnings: false,
  28. errors: true
  29. },
  30. proxy: {
  31. '/pb/mock': {
  32. target: 'http://127.0.0.1:4523/mock/349485',//目标地址
  33. changeOrigin: true, //开启代理:在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求的数据,这样服务端和服务端进行数据的交互就不会有跨域问题
  34. pathRewrite: {
  35. '^/pb/mock': '/'
  36. }, //这里重写路径
  37. logLevel: 'debug',
  38. },
  39. '/pb': {
  40. // target: 'http://192.168.1.122:9100/',
  41. // target: 'http://192.168.110.67:9100/',
  42. // target: 'http://192.168.110.67:9888',
  43. target: 'http://192.168.110.138:8090/',
  44. // target: 'http://192.168.110.82:8090/',
  45. // target: 'http://192.168.1.109:9100/',
  46. // target: 'https://standard-dev.winsea.com/',
  47. changeOrigin: true, //开启代理:在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求的数据,这样服务端和服务端进行数据的交互就不会有跨域问题
  48. pathRewrite: {
  49. '^/pb': '/'
  50. }, //这里重写路径
  51. secure: false,
  52. logLevel: 'debug',
  53. },
  54. },
  55. after(app) {
  56. require('@babel/register')
  57. const bodyParser = require('body-parser')
  58. // parse app.body
  59. // http://expressjs.com/en/4x/api.html#req.body
  60. app.use(bodyParser.json())
  61. app.use(
  62. bodyParser.urlencoded({
  63. extended: true
  64. })
  65. )
  66. // const { default: mocks } = require('./mock')
  67. // for (const mock of mocks) {
  68. // app[mock.type](mock.url, mock.response)
  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. config.plugins.delete('preload') // TODO: need test
  84. config.plugins.delete('prefetch') // TODO: need test
  85. // set svg-sprite-loader
  86. config.module
  87. .rule('svg')
  88. .exclude.add(resolve('src/assets/icons'))
  89. .end()
  90. config.module
  91. .rule('icons')
  92. .test(/\.svg$/)
  93. .include.add(resolve('src/assets/icons'))
  94. .end()
  95. .use('svg-sprite-loader')
  96. .loader('svg-sprite-loader')
  97. .options({
  98. symbolId: 'icon-[name]'
  99. })
  100. .end()
  101. // set preserveWhitespace
  102. config.module
  103. .rule('vue')
  104. .use('vue-loader')
  105. .loader('vue-loader')
  106. .tap(options => {
  107. options.compilerOptions.preserveWhitespace = true
  108. return options
  109. })
  110. .end()
  111. config.when(process.env.NODE_ENV === 'development', config =>
  112. config.devtool('cheap-source-map')
  113. )
  114. config.when(process.env.NODE_ENV !== 'development', 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.optimization.splitChunks({
  124. chunks: 'all',
  125. cacheGroups: {
  126. libs: {
  127. name: 'chunk-libs',
  128. test: /[\\/]node_modules[\\/]/,
  129. priority: 10,
  130. chunks: 'initial' // only package third parties that are initially dependent
  131. },
  132. elementUI: {
  133. name: 'chunk-elementUI', // split elementUI into a single package
  134. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  135. test: /[\\/]node_modules[\\/]element-ui[\\/]/
  136. },
  137. commons: {
  138. name: 'chunk-commons',
  139. test: resolve('src/components'), // can customize your rules
  140. minChunks: 3, // minimum common number
  141. priority: 5,
  142. reuseExistingChunk: true
  143. }
  144. }
  145. })
  146. config.optimization.runtimeChunk('single')
  147. })
  148. }
  149. }