vue.config.js 4.8 KB

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