First you need to download YUI Compressor from Yahoo and unzip its contents anywhere.
Now you want to make a new external tool in Visual Studio. (Tools -> External Tools...)
Then add a new tool and name it YUI Compressor. You want to put the following values in the inputs. Adjust the jar location depending of where you unzipped YUI Compressor. It also assumes that java.exe is in your path.
- Title: Yui Compressor
- Command: java.exe
- Arguments: -jar "E:\yuicompressor-2.4.2\build\yuicompressor-2.4.2.jar" $(ItemPath) --charset "UTF8" --type js -o $(ItemFileName).min$(ItemExt)
- Initial Directory: $(ItemDir)
- Check “Use Output Window”
You can already test this. Any problems will be presented in the Output window. First you need to select your *.js file in the Solution Explorer. Then in the Tool menu, select Yui Compressor. Refresh the directory that contains your *.js file and you should have a file named *.min.js with the same prefix as your *.js.
You could do the same thing to minimize CSS just by making a new external tool with the –type argument value changed to css instead of js.
You can easily make a toolbar to quickly do this when you need it. Go to Tools->Customize. Then New…
Then go to the Command Tab and select Tools.
Drag and Drop the External Command 1 (or the # corresponding to your external tool if you have more than one) to the created toolbar. Hit close and now you can put your new toolbar wherever you want.
I hope you find this useful! Setting up tools this way inside Visual Studio is a good way to speed up the development process because you don't need to memorize numerous command line parameters: everything is done with one click!