vue.config.js 4.7 KB

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