5

The issue

I'm using uglify-js to minify some js code. I am using it like so:

uglifyjs --compress --mangle file.js -o outfile.min.js

However, this causes it to hang and never complete. I can get a successful output from uglify if I remove "--compress" and "--mangle", e.g.:

uglifyjs file.js -o outfile.min.js

However, I want to use those options of course.

My setup

Windows 7 Ultimate x64. Console is bash.

Not sure what other details are pertinent for this (except versions of the relevant tools, but see below).

Things I've tried

Searching the internet.

Updating my Node-js install:

node -v
v10.15.3

Updating my uglify-js install:

uglifyjs -V
uglify-js 3.4.9

Running uglifyjs with --verbose. Nothing is output.

Running uglifyjs on files directly in my current directory (no change).

1 Answers1

7

You have to pass the list of files to minify before the options list.

uglifyjs [input files] [options]

So you should have this instead:

uglifyjs file.js --compress --mangle -o outfile.min.js

Alternatively, from the documentation:

If you wish to pass your options before the input files, separate the two with a double dash to prevent input files being used as option arguments:

uglifyjs --compress --mangle -- input.js

  • 1
    Wow, what a weird one, shouldn't they give some sort of error or warning if they are not getting any input? I'm assuming they're expecting STDIN though. Still pretty bad UX, CLI wise. – Shubham Kushwah Sep 02 '21 at 15:39
  • If this is true, which it appears to be because the solution worked in my case...it's a pretty bad bug in the CLI! – Josh M. May 20 '22 at 14:15