Presets
A preset is just an object with modules config.
Currently the following presets are available:
- safe — default preset for safe minification.
- ampSafe — same as
safebut tailored 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;
htmlnano.process(html, { collapseWhitespace: 'conservative' }, ampSafePreset)
.then((result) => {
// result.html is minified
})
.catch((err) => {
console.error(err);
});
You can also import presets directly:
import htmlnano from 'htmlnano';
import ampSafe from 'htmlnano/presets/ampSafe';
const result = await htmlnano.process(html, {}, ampSafe);
If you skip preset argument, safe is 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 your own presets by starting from a built-in one:
const htmlnano = require('htmlnano');
const emailPreset = {
...htmlnano.presets.safe,
mergeStyles: true,
minifyCss: {
safe: true
}
};
htmlnano.process(html, { removeComments: false }, emailPreset)
.then((result) => {
// result.html is minified
})
.catch((err) => {
console.error(err);
});
Feel free to submit a PR with your preset if it might be useful for other developers as well.