Skip to content

Commit

Permalink
support asynchronous uglify modules
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Aug 21, 2020
1 parent ed6ace8 commit 5c853fb
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,24 @@ function uglifyStream (opts) {
var stream = duplexify()

var writer = concat({ encoding: 'string' }, function (source) {
var minified = uglify.minify(source, opts)
if (minified.error) {
stream.emit('error', minified.error)
return
var result = uglify.minify(source, opts)
if (result.then) {
result.then(onsuccess, onerror)
} else if (result.error) {
return onerror(result.error)
} else onsuccess(result)

function onsuccess (minified) {
var final = minified.code
if (minified.map) {
final += '\n' + convert.fromJSON(minified.map).toComment()
}
var reader = fromString(final)
stream.setReadable(reader)
}
var final = minified.code
if (minified.map) {
final += '\n' + convert.fromJSON(minified.map).toComment()
function onerror (error) {
stream.emit('error', error)
}
var reader = fromString(final)
stream.setReadable(reader)
})

stream.setWritable(writer)
Expand Down

0 comments on commit 5c853fb

Please sign in to comment.