vue.config.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 || 'vue Admin Template' // 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. // http://192.168.3.28:8000
  16. // let target = 'http://192.168.3.27:8000' //箭河大佬
  17. let target = 'http://192.168.3.28:8000' //邹璇
  18. // let target = 'http://192.168.3.8:8000' //勇哥
  19. // let target = 'http://47.99.212.176:8000' // 测试服
  20. // let target = 'http://192.168.3.48:8000' // 乔
  21. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  22. module.exports = {
  23. /**
  24. * You will need to set publicPath if you plan to deploy your site under a sub path,
  25. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  26. * then publicPath should be set to "/bar/".
  27. * In most cases please use '/' !!!
  28. * Detail: https://cli.vuejs.org/config/#publicpath
  29. */
  30. publicPath: './',
  31. outputDir: 'dist',
  32. assetsDir: 'static',
  33. lintOnSave: false,
  34. productionSourceMap: false,
  35. devServer: {
  36. // port: port,
  37. open: true,
  38. // overlay: {
  39. // warnings: false,
  40. // errors: true
  41. // },
  42. proxy: {
  43. // change xxx-api/login => mock/login
  44. // detail: https://cli.vuejs.org/config/#devserver-proxy
  45. // http://47.99.212.176:8000
  46. // http://192.168.3.28:8000
  47. '/api-auth': {
  48. target: target,
  49. changeOrigin: true,
  50. pathRewrite: {
  51. '^api-auth': ''
  52. }
  53. },
  54. '/web-server': {
  55. target: target,
  56. changeOrigin: true,
  57. pathRewrite: {
  58. '^web-server': ''
  59. }
  60. },
  61. '/jiari': {
  62. target: 'http://tool.bitefu.net',
  63. changeOrigin: true,
  64. }
  65. },
  66. },
  67. configureWebpack: {
  68. // provide the app's title in webpack's name field, so that
  69. // it can be accessed in index.html to inject the correct title.
  70. name: name,
  71. resolve: {
  72. alias: {
  73. '@': resolve('src')
  74. }
  75. }
  76. },
  77. chainWebpack (config) {
  78. config.plugins.delete('preload') // TODO: need test
  79. config.plugins.delete('prefetch') // TODO: need test
  80. // set svg-sprite-loader
  81. config.module
  82. .rule('svg')
  83. .exclude.add(resolve('src/icons'))
  84. .end()
  85. config.module
  86. .rule('icons')
  87. .test(/\.svg$/)
  88. .include.add(resolve('src/icons'))
  89. .end()
  90. .use('svg-sprite-loader')
  91. .loader('svg-sprite-loader')
  92. .options({
  93. symbolId: 'icon-[name]'
  94. })
  95. .end()
  96. // set preserveWhitespace
  97. config.module
  98. .rule('vue')
  99. .use('vue-loader')
  100. .loader('vue-loader')
  101. .tap(options => {
  102. options.compilerOptions.preserveWhitespace = true
  103. return options
  104. })
  105. .end()
  106. config
  107. // https://webpack.js.org/configuration/devtool/#development
  108. .when(process.env.NODE_ENV === 'development',
  109. config => config.devtool('cheap-source-map')
  110. )
  111. config
  112. .when(process.env.NODE_ENV !== 'development',
  113. config => {
  114. config
  115. .plugin('ScriptExtHtmlWebpackPlugin')
  116. .after('html')
  117. .use('script-ext-html-webpack-plugin', [{
  118. // `runtime` must same as runtimeChunk name. default is `runtime`
  119. inline: /runtime\..*\.js$/
  120. }])
  121. .end()
  122. config
  123. .optimization.splitChunks({
  124. chunks: 'all',
  125. cacheGroups: {
  126. libs: {
  127. name: 'chunk-libs',
  128. test: /[\\/]node_modules[\\/]/,
  129. priority: 10,
  130. chunks: 'initial' // only package third parties that are initially dependent
  131. },
  132. elementUI: {
  133. name: 'chunk-elementUI', // split elementUI into a single package
  134. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  135. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  136. },
  137. commons: {
  138. name: 'chunk-commons',
  139. test: resolve('src/components'), // can customize your rules
  140. minChunks: 3, // minimum common number
  141. priority: 5,
  142. reuseExistingChunk: true
  143. }
  144. }
  145. })
  146. config.optimization.runtimeChunk('single')
  147. }
  148. )
  149. }
  150. }