vue.config.js 5.2 KB

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