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