vue.config.js 5.4 KB

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