Closed tamtakoe closed 8 years ago
what are your requirements for doing it sync?
For example, If I caches templates
templates.forEach(function(template) {
templatesCache.push(minimize.parseSync(template))
})
or other minor situations when it is uncomfortable to work with callbacks
Hmm i can see the usecase. However this is slightly out of minimizes' control. E.g. the DOMParser which is used by htmlparser2 is working with a callback https://github.com/fb55/domhandler#example. The only way this could work is if all 3 modules (minimize->htmlparser2->domhandler) would be working sync. Alternative solution to you caching.
require('async').map(templates, minimize.parse.bind(minimize), function (err, results) {
templatesCache = results;
})
or similar
I made issue https://github.com/fb55/domhandler/issues/21
https://github.com/kangax/html-minifier works synchronously, but has verbose API and has not gulp plugin.
@Swaagie Calling the functions of the modules is a synchronous operation. Simply process the file, then access domhandler's dom
property. The callback is also synchronous, you could have the handler assign the value to a local variable, then return it (not a nice solution, but works as well).
@fb55 thanks for replying :) As for the feature request, I hope I can spend a cycle on it this weekend.
Kinda fell of the radar, I'll try to spend a cycle on it asap
Looking for the sync feature :)
Finally fixed with https://github.com/Swaagie/minimize/pull/80 and released as 2.0.0
Minimize synchronously as
minimize.parseSync