vue.config.js 6.1 KB

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