vue.config.js 5.5 KB

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