krekto
krekto

Reputation: 1487

Uglify.JS minifies filename instead of file contents

I'm using uglifyjs to minify js files, but when I run the tool it minifies the file name I passed and not the content.

var resultugly = UglifyJS.minify(['app_client/app.js']);
console.log(resultugly.code);

and the log result is: app_client,app.js; not the file content

Can someone help me please ?

Upvotes: 0

Views: 614

Answers (1)

krekto
krekto

Reputation: 1487

I solved the problem, what happens is that I need to use the function readFileSync from the 'fs' module before to import the file, for example:

var appClientFiles = [
  fs.readFileSync('app_client/app.js', "utf8")
];

then just pass the vector with the or files as a parameter of the uglify minify function as below:

var resultugly = UglifyJS.minify(appClientFiles);

I hope I can help someone

Upvotes: 2

Related Questions