vue.config.js 5.6 KB

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