I selected terser as the first one: I’m not particularly bothered about speed (I only minify occasionally, it’s not like I’m always altering the JS for this site, so speed is not a big worry) and so I went for the minifier that produced the smallest output. One quick call to
npm install terser –g later, I was ready to go.
rem minify Boyet script terser [input files] -o js\minifiedBoyet.js -c rem minify Boyet God script terser [input files] -o js\minifiedBoyetGod.js -c
I ran the batch file and it just stopped after executing the first (successful) call to
terser. The second call never happened. Wut? The first minified JS file had been created, and looked OK, but the second was nowhere to be seen. Double wut?
Time for a bit of googling. First hint was to put each of the calls to
terser in their own batch files, so all the main batch file does is to call the two one-line batch files. Didn’t work. Turns out that when you call a batch file from another, the called batch file doesn’t return: some historical reason dating from MS-DOS days. You have to explicitly
call the secondary batch file, like this:
call DoThisOtherThing.bat. Well I never, and I’ve been programming PCs since those MS-DOS days.
OK, bingo, here we go! Except nope, still didn’t work: the batch files just stopped after that first call to
This took another bit of googling. It turns out that
terser is not a batch file, nor an
exe file, but a
terser.cmd. To run a
cmd file inside a batch file, you have to use … get ready for it … the
cmd command. With the
/c switch so that it can return.
Boom, this is the batch file that actually worked as I’d expected:
rem minify Boyet script cmd /c terser [input files]] -o js\minifiedBoyet.js -c rem minify Boyet God script cmd /c terser [input files]] -o js\minifiedBoyetGod.js -c
Now, what was I doing all this for again? Oh yes, minification. Time to test these new minified files to see that all their functionality works as before…