Minify multiple Javascript files in a folder with UglifyJS

To minify multiple Javascript files, you can use Grunt. However, there is a much easier way to archive it using UglifyJS and Bashscript.

Step 1: Install UglifyJS

1npm install -g uglify-js

Step 2: Write some Bash script code to find and minify all js files in a folder

1for file in path/to/js/folder/*.js; do
2    uglifyjs "$file" --stats -c -m  -o "$file" 
3    echo minified: "$file" 
4done 

Step 3: Run script

Save script in Step 2 to a file called 'minify-js.sh' and run it using Terminal:

1sudo chmod +x minify-js.sh
2./minify-js.sh

Modify this code a litte and you can use it with cleancss or other minifier.

This code help me much in deploying my webiste (a static site built with Jekyll). Hope it help someone else.

Related Posts

Một số kĩ thuật xử lí tiếng Việt trong Javascript

Các kĩ thuật xử lí sau sẽ giúp chúng ta thao tác với tiếng Việt dễ dàng hơn mà không cần mất công xây dựng lại.

Read more

Airflow, MLflow or Kubeflow for MLOps?

Machine learning is now focusing more on the data (data-centric AI), and MLOps is obviously the way to bring ML projects into production.

Read more

With Daisykit – Everyone can build AI projects!

Imagine you are a software engineer or a DIY hobbyist with great ideas to build AI-powered projects. However, it will be such difficulty when you know very little or nothing about AI.

Read more