vue.config.js 5.7 KB

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