html.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* сжимаем код через htmlMinify */
  2. 'use strict';
  3. const assert = require('assert');
  4. const Minifier = require('html-minifier');
  5. const Options = {
  6. removeComments: true,
  7. removeCommentsFromCDATA: true,
  8. removeCDATASectionsFromCDATA: true,
  9. collapseWhitespace: true,
  10. collapseBooleanAttributes: true,
  11. removeAttributeQuotes: true,
  12. removeRedundantAttributes: true,
  13. useShortDoctype: true,
  14. removeEmptyAttributes: true,
  15. /* оставляем, поскольку у нас
  16. * в элемент fm генерируеться
  17. * таблица файлов
  18. */
  19. removeEmptyElements: false,
  20. removeOptionalTags: true,
  21. removeScriptTypeAttributes: true,
  22. removeStyleLinkTypeAttributes: true,
  23. minifyJS: true,
  24. minifyCSS: true,
  25. };
  26. /**
  27. * minify html data.
  28. *
  29. * @param data
  30. * @param callback
  31. */
  32. module.exports = (data) => {
  33. assert(data);
  34. return Minifier.minify(data, Options);
  35. };