Execute multiple terser commands (compression/mangling) inside a .bat file

711 views Asked by At

Terser is a free tool for compressing and/or mangling javascript files.

As far as I have understood, the tool relies on node.js, so that is a pre-req for running Terser in the first place.

This will execute the terser command on a single file:

terser input.js -c -m -o output.js

This is fine for some files that aren't updated frequently, but if you have a large set of Javascript files in your project that are updated instantly, you would appreciate something more dynamic.

I was thinking about including each file command inside a .bat file and execute that as one file, but I cannot get that to work: I tried placing these between the ECHO AND PAUSE commands in the bat file but it doesn't work well unfortunately.

As far as I have seen, the documentation covers just running terser as CLI

Is there a way to "move" the command lines from the CLI environment to the .bat file?

2

There are 2 answers

0
RVB On

I encountered the same problem today as I was trying to use "terser" in batch files for the first time (instead of uglify-es I used precedently)

After each "terser" command the execution of the batch file stops

After adding a pipe | pause at the end of each terser command, my batch file runs as usual and executes the next commands.

0
Olivier C On

I encountered the same problem as you.

I can dynamically concatenate several files into one:

"terser scripts/development/main/* -o scripts/main.js --compress --mangle"

On the other hand, I haven't found a solution to dynamically render one for one (what we can do with PostCSS which benefits from the --dir option.)...