vue.config.js 4.5 KB

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