Prerequisite: nodejs should be installed on your system.
1. Installing terser
Install terser using
npm i terser -g
2. Creating a script
Add the script to
package.json file of your project.
"minify": "terser src/js/app.js -c -m --output src/minified/app.min.js"
src/minified/app.min.js with your input and output file path respectively.
-c flag stands for
-m stands for
--mangle. For more options, visit the official documentation of terser.
3. Executing the script
Run the script using this command:
npm run minify
You can also try terser on the web.
Originally published at https://syntackle.live on August 8, 2022.