vue.config.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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://192.168.3.139:8000' // 箭河
  21. // let target = 'http://192.168.3.124:8000' //邹璇
  22. // let target = 'http://192.168.3.119:8000' //勇哥
  23. let target = 'http://dev.dayaedu.com' // 开发环境
  24. // let target = 'https://test.dayaedu.com' //测试环境
  25. // let target = 'http://192.168.3.134:8000' // 乔
  26. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  27. module.exports = {
  28. /**
  29. * You will need to set publicPath if you plan to deploy your site under a sub path,
  30. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  31. * then publicPath should be set to "/bar/".
  32. * In most cases please use '/' !!!
  33. * Detail: https://cli.vuejs.org/config/#publicpath
  34. */
  35. publicPath: './',
  36. outputDir: 'dist',
  37. assetsDir: 'static',
  38. lintOnSave: false,
  39. productionSourceMap: false,
  40. // 以下是pwa配置
  41. pwa: {
  42. iconPaths: {
  43. favicon32: 'favicon1.ico',
  44. favicon16: 'favicon1.ico',
  45. appleTouchIcon: 'favicon1.ico',
  46. maskIcon: 'favicon1.ico',
  47. msTileImage: 'favicon1.ico'
  48. }
  49. },
  50. devServer: {
  51. disableHostCheck: true,
  52. open: false,
  53. hot: true,
  54. port:3005,
  55. // overlay: {
  56. // warnings: false,
  57. // errors: true
  58. // },
  59. // https: true,
  60. proxy: {
  61. // change xxx-api/login => mock/login
  62. // detail: https://cli.vuejs.org/config/#devserver-proxy
  63. // http://47.99.212.176:8000
  64. // http://192.168.3.28:8000
  65. // http://192.168.3.134
  66. // http://47.114.176.40:8000
  67. // let target = 'http://dev.dayaedu.com'
  68. // 'http://dev.dayaedu.com'
  69. '/api-auth': {
  70. target: target,
  71. // target : target,
  72. changeOrigin: true,
  73. pathRewrite: {
  74. '^api-auth': ''
  75. }
  76. },
  77. '/api-task': {
  78. target: target,
  79. changeOrigin: true,
  80. pathRewrite: {
  81. '^api-task': ''
  82. }
  83. },
  84. '/api-web': {
  85. target: target,
  86. changeOrigin: true,
  87. pathRewrite: {
  88. '^api-web': ''
  89. }
  90. },
  91. '/api-cms': {
  92. target: target,
  93. changeOrigin: true,
  94. pathRewrite: {
  95. '^api-cms': ''
  96. }
  97. },
  98. '/api-teacher': {
  99. target: target,
  100. changeOrigin: true,
  101. pathRewrite: {
  102. '^api-teacher': ''
  103. }
  104. },
  105. '/api-oa': {
  106. target: target,
  107. changeOrigin: true,
  108. pathRewrite: {
  109. '^api-oa': ''
  110. }
  111. },
  112. '/jiari': {
  113. target: 'http://tool.bitefu.net',
  114. changeOrigin: true,
  115. },
  116. '/instructions': {
  117. target: defaultSettings.instructions,
  118. changeOrigin: true,
  119. },
  120. // instructions
  121. },
  122. },
  123. configureWebpack: {
  124. // provide the app's title in webpack's name field, so that
  125. // it can be accessed in index.html to inject the correct title.
  126. name: name,
  127. resolve: {
  128. alias: {
  129. '@': resolve('src'),
  130. '@scss':path.resolve(__dirname,'src')
  131. }
  132. }
  133. },
  134. chainWebpack(config) {
  135. config.plugins.delete('preload') // TODO: need test
  136. config.plugins.delete('prefetch') // TODO: need test
  137. config.resolve.symlinks(true);
  138. // set svg-sprite-loader
  139. config.module
  140. .rule('svg')
  141. .exclude.add(resolve('src/icons'))
  142. .end()
  143. config.module
  144. .rule('icons')
  145. .test(/\.svg$/)
  146. .include.add(resolve('src/icons'))
  147. .end()
  148. .use('svg-sprite-loader')
  149. .loader('svg-sprite-loader')
  150. .options({
  151. symbolId: 'icon-[name]'
  152. })
  153. .end()
  154. // set preserveWhitespace
  155. config.module
  156. .rule('vue')
  157. .use('vue-loader')
  158. .loader('vue-loader')
  159. .tap(options => {
  160. options.compilerOptions.preserveWhitespace = true
  161. return options
  162. })
  163. .end()
  164. config
  165. // https://webpack.js.org/configuration/devtool/#development
  166. .when(process.env.NODE_ENV === 'development',
  167. config => config.devtool('cheap-source-map')
  168. )
  169. config
  170. .when(process.env.NODE_ENV !== 'development',
  171. config => {
  172. config
  173. .plugin('ScriptExtHtmlWebpackPlugin')
  174. .after('html')
  175. .use('script-ext-html-webpack-plugin', [{
  176. // `runtime` must same as runtimeChunk name. default is `runtime`
  177. inline: /runtime\..*\.js$/
  178. }])
  179. .end()
  180. config
  181. .optimization.splitChunks({
  182. chunks: 'all',
  183. cacheGroups: {
  184. libs: {
  185. name: 'chunk-libs',
  186. test: /[\\/]node_modules[\\/]/,
  187. priority: 10,
  188. chunks: 'initial' // only package third parties that are initially dependent
  189. },
  190. elementUI: {
  191. name: 'chunk-elementUI', // split elementUI into a single package
  192. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  193. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  194. },
  195. commons: {
  196. name: 'chunk-commons',
  197. test: resolve('src/components'), // can customize your rules
  198. minChunks: 3, // minimum common number
  199. priority: 5,
  200. reuseExistingChunk: true
  201. }
  202. }
  203. })
  204. config.optimization.runtimeChunk('single')
  205. }
  206. )
  207. }
  208. }