Skip to main content
Version: 2.0.0

Presets

A preset is just an object with modules config.

Currently the following presets are available:

  • safe — a default preset for minifying a regular HTML in a safe way (without breaking anything)
  • ampSafe - same as safe preset but for AMP pages
  • max - maximal minification (might break some pages)

You can use them the following way:

const htmlnano = require('htmlnano');
const ampSafePreset = require('htmlnano').presets.ampSafe;
const options = {
// Your options
};

htmlnano
.process(html, options, ampSafePreset)
.then(function (result) {
// result.html is minified
})
.catch(function (err) {
console.error(err);
});

If you skip preset argument safe preset would be used by default.

If you'd like to define your very own config without any presets pass an empty object as a preset:

const htmlnano = require('htmlnano');
const options = {
// Your options
};

htmlnano
.process(html, options, {})
.then(function (result) {
// result.html is minified
})
.catch(function (err) {
console.error(err);
});

You might create also your own presets:

const htmlnano = require('htmlnano');
// Preset for minifying email templates
const emailPreset = {
mergeStyles: true,
minifyCss: {
safe: true
},
};

const options = {
// Some specific options
};

htmlnano
.process(html, options, emailPreset)
.then(function (result) {
// result.html is minified
})
.catch(function (err) {
console.error(err);
});

Feel free to submit a PR with your preset if it might be useful for other developers as well.