vue.config.js 5.6 KB

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