Minifying js/css content in-memory?
hlubovac opened this issue · 2 comments
hlubovac commented
Hello - I'm curious why there isn't a method for this that doesn't involve having content in files? I have a use-case where I have a JS snippet loaded in memory (variable), and I'd like to produce a minified version without first writing it to a file, then reading from output file, then worrying about that clean-up on top of that. I thought, maybe it's trivial for you to implement.
Thanks.
srod commented
It's live in 5.1.0
You can use it like that:
const html = `
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
</html>
`;
minify({
compressor: htmlMinifier,
content: html,
options: {
minifyJS: false
},
callback: function(err, min) {
console.log('callback min');
console.log(min);
}
}).then(function(min) {
console.log('html min');
console.log(min);
});
You need to pass the compressor according the content (html, css, javascript).
I will see if I can find a solution to detect content type and use defaults compressors.
You can also still pass options to the compressor.