vue.config.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. function resolve (dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. const name = defaultSettings.title || 'vue Admin Template' // page title
  8. // If your port is set to 80,
  9. // use administrator privileges to execute the command line.
  10. // For example, Mac: sudo npm run
  11. // You can change the port by the following methods:
  12. // port = 9528 npm run dev OR npm run dev --port = 9528
  13. // const port = process.env.port || process.env.npm_config_port || 9528 // dev port
  14. // http://47.99.212.176:8000
  15. // http://192.168.3.28:8000
  16. // let target = 'http://192.168.3.28:8000' //邹璇
  17. // let target = 'http://192.168.3.8:8000' //勇哥
  18. // let target = 'http://47.99.212.176:8000' // 测试服
  19. let target = 'http://192.168.3.48:8000' // 乔
  20. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  21. module.exports = {
  22. /**
  23. * You will need to set publicPath if you plan to deploy your site under a sub path,
  24. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  25. * then publicPath should be set to "/bar/".
  26. * In most cases please use '/' !!!
  27. * Detail: https://cli.vuejs.org/config/#publicpath
  28. */
  29. publicPath: './',
  30. outputDir: 'dist',
  31. assetsDir: 'static',
  32. lintOnSave: false,
  33. productionSourceMap: false,
  34. devServer: {
  35. // port: port,
  36. open: true,
  37. // overlay: {
  38. // warnings: false,
  39. // errors: true
  40. // },
  41. proxy: {
  42. // change xxx-api/login => mock/login
  43. // detail: https://cli.vuejs.org/config/#devserver-proxy
  44. // http://47.99.212.176:8000
  45. // http://192.168.3.28:8000
  46. '/auth-server': {
  47. target: target,
  48. changeOrigin: true,
  49. pathRewrite: {
  50. '^auth-server': ''
  51. }
  52. },
  53. '/web-server': {
  54. target: target,
  55. changeOrigin: true,
  56. pathRewrite: {
  57. '^web-server': ''
  58. }
  59. },
  60. '/teacher-server': {
  61. target: target,
  62. changeOrigin: true,
  63. pathRewrite: {
  64. '^teacher-server': ''
  65. }
  66. },
  67. '/jiari': {
  68. target: 'http://tool.bitefu.net',
  69. changeOrigin: true,
  70. }
  71. },
  72. },
  73. configureWebpack: {
  74. // provide the app's title in webpack's name field, so that
  75. // it can be accessed in index.html to inject the correct title.
  76. name: name,
  77. resolve: {
  78. alias: {
  79. '@': resolve('src')
  80. }
  81. }
  82. },
  83. chainWebpack (config) {
  84. config.plugins.delete('preload') // TODO: need test
  85. config.plugins.delete('prefetch') // TODO: need test
  86. // set svg-sprite-loader
  87. config.module
  88. .rule('svg')
  89. .exclude.add(resolve('src/icons'))
  90. .end()
  91. config.module
  92. .rule('icons')
  93. .test(/\.svg$/)
  94. .include.add(resolve('src/icons'))
  95. .end()
  96. .use('svg-sprite-loader')
  97. .loader('svg-sprite-loader')
  98. .options({
  99. symbolId: 'icon-[name]'
  100. })
  101. .end()
  102. // set preserveWhitespace
  103. config.module
  104. .rule('vue')
  105. .use('vue-loader')
  106. .loader('vue-loader')
  107. .tap(options => {
  108. options.compilerOptions.preserveWhitespace = true
  109. return options
  110. })
  111. .end()
  112. config
  113. // https://webpack.js.org/configuration/devtool/#development
  114. .when(process.env.NODE_ENV === 'development',
  115. config => config.devtool('cheap-source-map')
  116. )
  117. config
  118. .when(process.env.NODE_ENV !== 'development',
  119. 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
  129. .optimization.splitChunks({
  130. chunks: 'all',
  131. cacheGroups: {
  132. libs: {
  133. name: 'chunk-libs',
  134. test: /[\\/]node_modules[\\/]/,
  135. priority: 10,
  136. chunks: 'initial' // only package third parties that are initially dependent
  137. },
  138. elementUI: {
  139. name: 'chunk-elementUI', // split elementUI into a single package
  140. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  141. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  142. },
  143. commons: {
  144. name: 'chunk-commons',
  145. test: resolve('src/components'), // can customize your rules
  146. minChunks: 3, // minimum common number
  147. priority: 5,
  148. reuseExistingChunk: true
  149. }
  150. }
  151. })
  152. config.optimization.runtimeChunk('single')
  153. }
  154. )
  155. }
  156. }