maximum-size-transform.js 744 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. /*
  3. Copyright 2018 Google LLC
  4. Use of this source code is governed by an MIT-style
  5. license that can be found in the LICENSE file or at
  6. https://opensource.org/licenses/MIT.
  7. */
  8. const prettyBytes = require('pretty-bytes');
  9. module.exports = maximumFileSizeToCacheInBytes => {
  10. return originalManifest => {
  11. const warnings = [];
  12. const manifest = originalManifest.filter(entry => {
  13. if (entry.size <= maximumFileSizeToCacheInBytes) {
  14. return true;
  15. }
  16. warnings.push(`${entry.url} is ${prettyBytes(entry.size)}, and won't ` + `be precached. Configure maximumFileSizeToCacheInBytes to change ` + `this limit.`);
  17. return false;
  18. });
  19. return {
  20. manifest,
  21. warnings
  22. };
  23. };
  24. };