vue.config.js 5.6 KB

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