kangax / html-minifier

Javascript-based HTML compressor/minifier (with Node.js support)
http://kangax.github.io/html-minifier/
MIT License
4.93k stars 571 forks source link

No async support for minifyCSS and minifyJS ? #1088

Open devalexqt opened 3 years ago

devalexqt commented 3 years ago

No async support ?

153264 commented 3 years ago

I want to use Babel to escape ES6 code to ES5, but it returns a Promise and cannot be used with MinifyJS

ghost commented 3 years ago

@153264 Need more details.

devalexqt commented 3 years ago

Must accept async function, something like that:

minifyCSS/minifyJS: async (options)=>{
     var data=await bundle(...)
     ...
    return data
}
153264 commented 3 years ago
minifyJS: async function (text) {
                const res = await jsMinify(text, {
                    warnings: true
                })
                if (res.warnings) console.log(res.warnings)
                if (res.error) {
                    console.log(text)
                    throw res.error
                }
                // no console
                console.log('res', res)
                // Promise { <pending> }
                return res.code
            }

Promise { }

events.js:292 throw er; // Unhandled 'error' event ^ PluginError [TypeError]: attrValue.match is not a function at buildAttr (C:\Users\25635\Desktop\gulp\node_modules\html-minifier\src\htmlminifier.js:581:31) at Object.start (C:\Users\25635\Desktop\gulp\node_modules\html-minifier\src\htmlminifier.js:1040:25) at handleStartTag (C:\Users\25635\Desktop\gulp\node_modules\html-minifier\src\htmlparser.js:376:15) at new HTMLParser (C:\Users\25635\Desktop\gulp\node_modules\html-minifier\src\htmlparser.js:181:11) at minify (C:\Users\25635\Desktop\gulp\node_modules\html-minifier\src\htmlminifier.js:970:3) at Object.exports.minify (C:\Users\25635\Desktop\gulp\node_modules\html-minifier\src\htmlminifier.js:1330:16) at minify (C:\Users\25635\Desktop\gulp\node_modules\gulp-htmlmin\index.js:16:44) at DestroyableTransform._transform (C:\Users\25635\Desktop\gulp\node_modules\gulp-htmlmin\index.js:38:7) at DestroyableTransform.Transform._read (C:\Users\25635\Desktop\gulp\node_modules\readable-stream\lib_stream_transform.js:184:10) at DestroyableTransform.Transform._write (C:\Users\25635\Desktop\gulp\node_modules\readable-stream\lib_stream_transform.js:172:83) Emitted 'error' event on Domain instance at: