how to minify JavaScript files using Eclipse JSDT?

4.6k Views Asked by At

How to "build" *.min.js and *.min.js.map files using Eclipse JSDT (JavaScript Developement Tools)?

2

There are 2 best solutions below

5
BCG On

You can use an external builder to run build scripts for your Javascript tasks.

Go to Project --> Properties and choose Builders. Then you can add an external builder to launch an external program with whatever arguments you need.

Setting up an external builder for NPM

You can se the builder to run automatically by using the Build Options tab and setting the "Run The Builder:" options:

enter image description here

1
Ecliptica On

I use YUICompressor. It works on both JavaScript and CSS. Once it's installed, it's easy to use:

  1. Right-click the JS file you'd like to minimize
  2. Go to External Tools > Compress Javascript
  3. Specify the name of the compressed file and click Finish

Unfortunately, you will need to manually run the compressor every time you change the original file, which can get tedious if you're working with lots of files. If you want to automate the process, see this answer. I ended up writing a quick batch script for my project.