vue.config.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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.112: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: false,
  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. '/api-oa': {
  102. target: target,
  103. changeOrigin: true,
  104. pathRewrite: {
  105. '^api-oa': ''
  106. }
  107. },
  108. '/jiari': {
  109. target: 'http://tool.bitefu.net',
  110. changeOrigin: true,
  111. },
  112. '/instructions': {
  113. target: defaultSettings.instructions,
  114. changeOrigin: true,
  115. },
  116. // instructions
  117. },
  118. },
  119. configureWebpack: {
  120. // provide the app's title in webpack's name field, so that
  121. // it can be accessed in index.html to inject the correct title.
  122. name: name,
  123. resolve: {
  124. alias: {
  125. '@': resolve('src')
  126. }
  127. }
  128. },
  129. chainWebpack (config) {
  130. config.plugins.delete('preload') // TODO: need test
  131. config.plugins.delete('prefetch') // TODO: need test
  132. // set svg-sprite-loader
  133. config.module
  134. .rule('svg')
  135. .exclude.add(resolve('src/icons'))
  136. .end()
  137. config.module
  138. .rule('icons')
  139. .test(/\.svg$/)
  140. .include.add(resolve('src/icons'))
  141. .end()
  142. .use('svg-sprite-loader')
  143. .loader('svg-sprite-loader')
  144. .options({
  145. symbolId: 'icon-[name]'
  146. })
  147. .end()
  148. // set preserveWhitespace
  149. config.module
  150. .rule('vue')
  151. .use('vue-loader')
  152. .loader('vue-loader')
  153. .tap(options => {
  154. options.compilerOptions.preserveWhitespace = true
  155. return options
  156. })
  157. .end()
  158. config
  159. // https://webpack.js.org/configuration/devtool/#development
  160. .when(process.env.NODE_ENV === 'development',
  161. config => config.devtool('cheap-source-map')
  162. )
  163. config
  164. .when(process.env.NODE_ENV !== 'development',
  165. config => {
  166. config
  167. .plugin('ScriptExtHtmlWebpackPlugin')
  168. .after('html')
  169. .use('script-ext-html-webpack-plugin', [{
  170. // `runtime` must same as runtimeChunk name. default is `runtime`
  171. inline: /runtime\..*\.js$/
  172. }])
  173. .end()
  174. config
  175. .optimization.splitChunks({
  176. chunks: 'all',
  177. cacheGroups: {
  178. libs: {
  179. name: 'chunk-libs',
  180. test: /[\\/]node_modules[\\/]/,
  181. priority: 10,
  182. chunks: 'initial' // only package third parties that are initially dependent
  183. },
  184. elementUI: {
  185. name: 'chunk-elementUI', // split elementUI into a single package
  186. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  187. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  188. },
  189. commons: {
  190. name: 'chunk-commons',
  191. test: resolve('src/components'), // can customize your rules
  192. minChunks: 3, // minimum common number
  193. priority: 5,
  194. reuseExistingChunk: true
  195. }
  196. }
  197. })
  198. config.optimization.runtimeChunk('single')
  199. }
  200. )
  201. }
  202. }