DEV: Use Terser for JS minification/compression if available (PR #12656)

Switches to Terser for JS compression, it is faster compared to uglify-js and supports more recent JS syntax (like the optional chaining operator).

Uglify-js is still used if terser is unavailable, but it will be removed at the next base image bump.

GitHub