Thursday, 25 May 2017

How to minify multiple files into one file using only uglifyjs?

I have tried to minify javascript files using uglifyjs into one file, but it's not working. I used $node uglifyjs.js to run the file. Below is the code in uglify.js

  var fs = require('fs');

  var uglifyjs = require('uglify-js');

  var files = ['app.js', 'geolocation.service.js'];

  var result = uglifyjs.minify(fs.readFileSync(files, 'utf8'));

 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.");
 }
 });

When I run this code I get the following error message:

  fs.js:549
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), 
  mode);
             ^

   TypeError: path must be a string
   at TypeError (native)
   at Object.fs.openSync (fs.js:549:18)
   at Object.fs.readFileSync (fs.js:397:15)
   at Object.<anonymous> (C:\Users\HP\Desktop\uglify\uglify.js:7:33)
   at Module._compile (module.js:435:26)
   at Object.Module._extensions..js (module.js:442:10)
   at Module.load (module.js:356:32)
   at Function.Module._load (module.js:311:12)
   at Function.Module.runMain (module.js:467:10)
   at startup (node.js:134:18)



via Maz

No comments:

Post a Comment