srod/node-minify

Any way to use in memory, without writing to a file?

bitttttten opened this issue ยท 5 comments

I would like to be able to do something like:

const minify = require('@node-minify/core');

const html = `
<!doctype html>
<html ${htmlAttributes}>
    <head>
        <meta charset="utf-8">
        <!-- ... -->
    </head>
</html>
`

console.log(minify(html))

Although on all the examples I see you have to pass in a file and output a file. Is it possible to do it in memory like above?

srod commented

Good idea, I will see that ๐Ÿ‘

Has any further work been done on this topic?

srod commented

Sorry, got no time lately.

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.

Awesome, thank you!