vue.config.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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:9888',
  42. target: 'http://192.168.110.138:8091/',
  43. // target: 'http://192.168.110.82:8090/',
  44. // target: 'http://192.168.1.109:9100/',
  45. // target: 'https://standard-dev.winsea.com/',
  46. changeOrigin: true, //开启代理:在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求的数据,这样服务端和服务端进行数据的交互就不会有跨域问题
  47. pathRewrite: {
  48. '^/pb': '/'
  49. }, //这里重写路径
  50. secure: false,
  51. logLevel: 'debug',
  52. },
  53. },
  54. after(app) {
  55. require('@babel/register')
  56. const bodyParser = require('body-parser')
  57. // parse app.body
  58. // http://expressjs.com/en/4x/api.html#req.body
  59. app.use(bodyParser.json())
  60. app.use(
  61. bodyParser.urlencoded({
  62. extended: true
  63. })
  64. )
  65. // const { default: mocks } = require('./mock')
  66. // for (const mock of mocks) {
  67. // app[mock.type](mock.url, mock.response)
  68. // }
  69. }
  70. },
  71. configureWebpack: {
  72. // provide the app's title in webpack's name field, so that
  73. // it can be accessed in index.html to inject the correct title.
  74. name: name,
  75. resolve: {
  76. alias: {
  77. '@': resolve('src')
  78. }
  79. }
  80. },
  81. chainWebpack(config) {
  82. config.plugins.delete('preload') // TODO: need test
  83. config.plugins.delete('prefetch') // TODO: need test
  84. // set svg-sprite-loader
  85. config.module
  86. .rule('svg')
  87. .exclude.add(resolve('src/assets/icons'))
  88. .end()
  89. config.module
  90. .rule('icons')
  91. .test(/\.svg$/)
  92. .include.add(resolve('src/assets/icons'))
  93. .end()
  94. .use('svg-sprite-loader')
  95. .loader('svg-sprite-loader')
  96. .options({
  97. symbolId: 'icon-[name]'
  98. })
  99. .end()
  100. // set preserveWhitespace
  101. config.module
  102. .rule('vue')
  103. .use('vue-loader')
  104. .loader('vue-loader')
  105. .tap(options => {
  106. options.compilerOptions.preserveWhitespace = true
  107. return options
  108. })
  109. .end()
  110. config.when(process.env.NODE_ENV === 'development', config =>
  111. config.devtool('cheap-source-map')
  112. )
  113. config.when(process.env.NODE_ENV !== 'development', config => {
  114. // config
  115. // .plugin('ScriptExtHtmlWebpackPlugin')
  116. // .after('html')
  117. // .use('script-ext-html-webpack-plugin', [{
  118. // // `runtime` must same as runtimeChunk name. default is `runtime`
  119. // inline: /runtime\..*\.js$/
  120. // }])
  121. // .end()
  122. config.optimization.splitChunks({
  123. chunks: 'all',
  124. cacheGroups: {
  125. libs: {
  126. name: 'chunk-libs',
  127. test: /[\\/]node_modules[\\/]/,
  128. priority: 10,
  129. chunks: 'initial' // only package third parties that are initially dependent
  130. },
  131. elementUI: {
  132. name: 'chunk-elementUI', // split elementUI into a single package
  133. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  134. test: /[\\/]node_modules[\\/]element-ui[\\/]/
  135. },
  136. commons: {
  137. name: 'chunk-commons',
  138. test: resolve('src/components'), // can customize your rules
  139. minChunks: 3, // minimum common number
  140. priority: 5,
  141. reuseExistingChunk: true
  142. }
  143. }
  144. })
  145. config.optimization.runtimeChunk('single')
  146. })
  147. }
  148. }