I have tried to minify javascript files using uglifyjs, but it's only outputting the file name in the file output.min.js followed by a semicolon and it's telling me that "File was successfully saved."; Not the minified code of the js file geolocation.service.js. Could anyone please help? The code below is saved in a file that I named uglifyjs. I used $node uglifyjs.js to run the file.
var fs = require('fs');
var uglifyjs = require('uglify-js');
var result = uglifyjs.minify(["geolocation.service.js"]);
console.log(result.code);
fs.writeFile("output.min.js", result.code, function(err) {
if(err) {
console.log(err);
} else {
console.log("File was successfully saved.");
}
});
The API is minify(code)
not minify(file paths)
uglifyjs.minify(fs.readFileSync('geolocation.service.js', 'utf8'))