vue.config.js 5.2 KB

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