UglifyJS - how to output to a different folder?

2.1k views Asked by At

I'm trying to use UglifyJS in order to minify my code but I'm running into a bit of a problem. I have a file structure like so:

/deploy
  /assets
    /js
      ((minified file goes here))
/js
  script-compiled.js

I want to run UglifyJS on js/script-compiled.js located in my private folder and have it output a script.min.js file in my deploy/js (the js that gets uploaded to my website) folder. Here's what I have so far for my command:

uglifyjs js/script-compiled.js --compress --mangle --screw-ie8 -o > deploy/assets/js/script.min.js

Which gives me this error:

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

TypeError: path must be a string

I'm a little confused. Is it possible to output a file to a different directory? Maybe this is just a general Bash thing. Thanks!

1

There are 1 answers

1
Felix Kling On BEST ANSWER

You specified the -o option but you didn't provide a value. From the docs:

-o filename or --output filename — put the result in filename. If this isn’t given, the result goes to standard output (or see next one).

So either do

uglifyjs ... -o deploy/assets/js/script.min.js

or omit -o and redirect stdout

uglifyjs ... > deploy/assets/js/script.min.js