vue.config.js 5.7 KB

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