vue.config.js 4.8 KB

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