vue.config.js 4.9 KB

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