vue.config.js 5.6 KB

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