expansive.es 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. Expansive.load({
  2. services: {
  3. name: 'html',
  4. options: '--remove-comments --collapse-whitespace --prevent-attributes-escaping --remove-empty-attributes --remove-optional-tags'
  5. transforms: {
  6. mappings: 'html',
  7. init: function(transform) {
  8. transform.htmlmin = Cmd.locate('html-minifier')
  9. if (!transform.htmlmin) {
  10. trace('Warn', 'Cannot find html-minifier')
  11. }
  12. },
  13. render: function(contents, meta, transform) {
  14. /*
  15. Only minify the final aggregation of document, partials and layout
  16. */
  17. if (meta.isLayout && !meta.layout && transform.htmlmin) {
  18. try {
  19. contents = run(transform.htmlmin + ' ' + transform.service.options, contents)
  20. contents += '\n'
  21. } catch (e) {
  22. if (expansive.options.debug) {
  23. print('Cannot minify', meta.source, '\n', e)
  24. print('Contents', contents)
  25. }
  26. /* Keep going with unminified contents */
  27. }
  28. }
  29. return contents
  30. }
  31. }
  32. }
  33. })