verify_vite_bundle_size.rb 770 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env ruby
  2. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  3. require 'yaml'
  4. require 'pathname'
  5. class VerifyViteBundleSize
  6. FILENAME = Pathname.new(__dir__).join('../tmp/vite-bundle-stats.yml')
  7. MAX_CHUNK_SIZE = 500 * 1_024
  8. def self.run
  9. puts 'Verifying vite bundle size…'
  10. YAML.load(FILENAME.read).each_pair do |chunk_name, chunk_files|
  11. chunk_size = 0
  12. chunk_files.each_value do |v|
  13. chunk_size += + v['gzip']
  14. end
  15. if chunk_size > MAX_CHUNK_SIZE
  16. raise "Chunk #{chunk_name} has a size of #{chunk_size}, which is higher than the allowed #{MAX_CHUNK_SIZE}.\n"
  17. end
  18. end
  19. puts "All chunks are smaller than the allowed #{MAX_CHUNK_SIZE}."
  20. end
  21. end
  22. VerifyViteBundleSize.run