vue.config.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * 配置参考:
  3. * https://cli.vuejs.org/zh/config/
  4. */
  5. const url = 'http://pigx-gateway:9999'
  6. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  7. const productionGzipExtensions = ['js', 'css']
  8. module.exports = {
  9. lintOnSave: true,
  10. productionSourceMap: false,
  11. chainWebpack: config => {
  12. // 忽略的打包文件
  13. config.externals({
  14. 'axios': 'axios'
  15. })
  16. const entry = config.entry('app')
  17. entry
  18. .add('babel-polyfill')
  19. .end()
  20. entry
  21. .add('classlist-polyfill')
  22. .end()
  23. },
  24. // eslint-disable-next-line
  25. configureWebpack: (config) => {
  26. if (process.env.NODE_ENV === 'production') {
  27. // 仅在生产环境下启用该配置
  28. return {
  29. plugins: [
  30. new CompressionWebpackPlugin({
  31. filename: '[path].gz[query]',
  32. algorithm: 'gzip',
  33. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  34. threshold: 1024, // 只有大小大于该值的资源会被处理,当前配置为对于超过1k的数据进行处理,不足1k的可能会越压缩越大
  35. minRatio: 0.99, // 只有压缩率小于这个值的资源才会被处理
  36. deleteOriginalAssets: true // 删除原文件
  37. })
  38. ]
  39. }
  40. }
  41. },
  42. // 配置转发代理
  43. devServer: {
  44. disableHostCheck: true,
  45. port: 8080,
  46. proxy: {
  47. '/': {
  48. target: url,
  49. ws: false, // 需要websocket 开启
  50. pathRewrite: {
  51. '^/': '/'
  52. }
  53. }
  54. // 3.5 以后不需要再配置
  55. }
  56. }
  57. }