html-minifier icon indicating copy to clipboard operation
html-minifier copied to clipboard

No async support for minifyCSS and minifyJS ?

Open devalexqt opened this issue 4 years ago • 4 comments

No async support ?

devalexqt avatar Mar 28 '21 12:03 devalexqt

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

153264 avatar Apr 23 '21 01:04 153264

@153264 Need more details.

ghost avatar Apr 23 '21 10:04 ghost

Must accept async function, something like that:

minifyCSS/minifyJS: async (options)=>{
     var data=await bundle(...)
     ...
    return data
}

devalexqt avatar Apr 23 '21 10:04 devalexqt

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:

153264 avatar Apr 23 '21 12:04 153264