vue.config.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. // change xxx-api/login => mock/login
  32. // detail: https://cli.vuejs.org/config/#devserver-proxy
  33. '/pb/api': {
  34. target: 'http://127.0.0.1:4523/mock/348176/',
  35. changeOrigin: true,
  36. secure: false,
  37. pathRewrite: {
  38. '^/pb/api': '/'
  39. }
  40. },
  41. '/pb/mock': {
  42. target: 'http://192.168.22.6:8020/',
  43. changeOrigin: true,
  44. secure: false,
  45. pathRewrite: {
  46. '^/pb/mock': '/'
  47. }
  48. },
  49. '/pb': {
  50. target: 'http://192.168.110.138:8090/',
  51. // target: 'http://192.168.110.82:8090/',
  52. // target: 'https://standard-dev.winsea.com/',
  53. pathRewrite: {
  54. '^/pb': '/'
  55. },
  56. changeOrigin: true,
  57. secure: false
  58. },
  59. },
  60. after(app) {
  61. require('@babel/register')
  62. const bodyParser = require('body-parser')
  63. // parse app.body
  64. // http://expressjs.com/en/4x/api.html#req.body
  65. app.use(bodyParser.json())
  66. app.use(
  67. bodyParser.urlencoded({
  68. extended: true
  69. })
  70. )
  71. // const { default: mocks } = require('./mock')
  72. // for (const mock of mocks) {
  73. // app[mock.type](mock.url, mock.response)
  74. // }
  75. }
  76. },
  77. configureWebpack: {
  78. // provide the app's title in webpack's name field, so that
  79. // it can be accessed in index.html to inject the correct title.
  80. name: name,
  81. resolve: {
  82. alias: {
  83. '@': resolve('src')
  84. }
  85. }
  86. },
  87. chainWebpack(config) {
  88. config.plugins.delete('preload') // TODO: need test
  89. config.plugins.delete('prefetch') // TODO: need test
  90. // set svg-sprite-loader
  91. config.module
  92. .rule('svg')
  93. .exclude.add(resolve('src/assets/icons'))
  94. .end()
  95. config.module
  96. .rule('icons')
  97. .test(/\.svg$/)
  98. .include.add(resolve('src/assets/icons'))
  99. .end()
  100. .use('svg-sprite-loader')
  101. .loader('svg-sprite-loader')
  102. .options({
  103. symbolId: 'icon-[name]'
  104. })
  105. .end()
  106. // set preserveWhitespace
  107. config.module
  108. .rule('vue')
  109. .use('vue-loader')
  110. .loader('vue-loader')
  111. .tap(options => {
  112. options.compilerOptions.preserveWhitespace = true
  113. return options
  114. })
  115. .end()
  116. config.when(process.env.NODE_ENV === 'development', config =>
  117. config.devtool('cheap-source-map')
  118. )
  119. config.when(process.env.NODE_ENV !== 'development', config => {
  120. // config
  121. // .plugin('ScriptExtHtmlWebpackPlugin')
  122. // .after('html')
  123. // .use('script-ext-html-webpack-plugin', [{
  124. // // `runtime` must same as runtimeChunk name. default is `runtime`
  125. // inline: /runtime\..*\.js$/
  126. // }])
  127. // .end()
  128. config.optimization.splitChunks({
  129. chunks: 'all',
  130. cacheGroups: {
  131. libs: {
  132. name: 'chunk-libs',
  133. test: /[\\/]node_modules[\\/]/,
  134. priority: 10,
  135. chunks: 'initial' // only package third parties that are initially dependent
  136. },
  137. elementUI: {
  138. name: 'chunk-elementUI', // split elementUI into a single package
  139. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  140. test: /[\\/]node_modules[\\/]element-ui[\\/]/
  141. },
  142. commons: {
  143. name: 'chunk-commons',
  144. test: resolve('src/components'), // can customize your rules
  145. minChunks: 3, // minimum common number
  146. priority: 5,
  147. reuseExistingChunk: true
  148. }
  149. }
  150. })
  151. config.optimization.runtimeChunk('single')
  152. })
  153. }
  154. }