Last active
March 17, 2021 20:09
-
-
Save daffl/5571372 to your computer and use it in GitHub Desktop.
Use UglifyJS 2 (uglify-js package) to compress a string of JavaScript source code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var UglifyJS = require('uglify-js'); | |
module.exports = function(code) { | |
var toplevel = UglifyJS.parse(code); | |
toplevel.figure_out_scope(); | |
var compressor = UglifyJS.Compressor({ | |
warnings: false | |
}); | |
var compressed = toplevel.transform(compressor); | |
compressed.figure_out_scope(); | |
compressed.compute_char_frequency(); | |
compressed.mangle_names(); | |
return compressed.print_to_string(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment