vue.config.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. '/api-auth': {
  48. target: target,
  49. changeOrigin: true,
  50. pathRewrite: {
  51. '^api-auth': ''
  52. }
  53. },
  54. '/api-web': {
  55. target: target,
  56. changeOrigin: true,
  57. pathRewrite: {
  58. '^api-web': ''
  59. }
  60. },
  61. '/api-cms': {
  62. target: target,
  63. changeOrigin: true,
  64. pathRewrite: {
  65. '^api-cms': ''
  66. }
  67. },
  68. '/api-teacher': {
  69. target: target,
  70. changeOrigin: true,
  71. pathRewrite: {
  72. '^api-teacher': ''
  73. }
  74. },
  75. '/jiari': {
  76. target: 'http://tool.bitefu.net',
  77. changeOrigin: true,
  78. }
  79. },
  80. },
  81. configureWebpack: {
  82. // provide the app's title in webpack's name field, so that
  83. // it can be accessed in index.html to inject the correct title.
  84. name: name,
  85. resolve: {
  86. alias: {
  87. '@': resolve('src')
  88. }
  89. }
  90. },
  91. chainWebpack (config) {
  92. config.plugins.delete('preload') // TODO: need test
  93. config.plugins.delete('prefetch') // TODO: need test
  94. // set svg-sprite-loader
  95. config.module
  96. .rule('svg')
  97. .exclude.add(resolve('src/icons'))
  98. .end()
  99. config.module
  100. .rule('icons')
  101. .test(/\.svg$/)
  102. .include.add(resolve('src/icons'))
  103. .end()
  104. .use('svg-sprite-loader')
  105. .loader('svg-sprite-loader')
  106. .options({
  107. symbolId: 'icon-[name]'
  108. })
  109. .end()
  110. // set preserveWhitespace
  111. config.module
  112. .rule('vue')
  113. .use('vue-loader')
  114. .loader('vue-loader')
  115. .tap(options => {
  116. options.compilerOptions.preserveWhitespace = true
  117. return options
  118. })
  119. .end()
  120. config
  121. // https://webpack.js.org/configuration/devtool/#development
  122. .when(process.env.NODE_ENV === 'development',
  123. config => config.devtool('cheap-source-map')
  124. )
  125. config
  126. .when(process.env.NODE_ENV !== 'development',
  127. config => {
  128. config
  129. .plugin('ScriptExtHtmlWebpackPlugin')
  130. .after('html')
  131. .use('script-ext-html-webpack-plugin', [{
  132. // `runtime` must same as runtimeChunk name. default is `runtime`
  133. inline: /runtime\..*\.js$/
  134. }])
  135. .end()
  136. config
  137. .optimization.splitChunks({
  138. chunks: 'all',
  139. cacheGroups: {
  140. libs: {
  141. name: 'chunk-libs',
  142. test: /[\\/]node_modules[\\/]/,
  143. priority: 10,
  144. chunks: 'initial' // only package third parties that are initially dependent
  145. },
  146. elementUI: {
  147. name: 'chunk-elementUI', // split elementUI into a single package
  148. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  149. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  150. },
  151. commons: {
  152. name: 'chunk-commons',
  153. test: resolve('src/components'), // can customize your rules
  154. minChunks: 3, // minimum common number
  155. priority: 5,
  156. reuseExistingChunk: true
  157. }
  158. }
  159. })
  160. config.optimization.runtimeChunk('single')
  161. }
  162. )
  163. }
  164. }