Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Visual Studio minify css and js on publish\compile

I have a project that works that works as a subapplication on a site (actually multiple sites). Among other things, I have several static css and js files in this project. I need to keep those as separate js and css files, but to keep google happy, I'd like to minify those. Those files are likely to be modified in the future, so I'd like to avoid manually minifying them every time they are changed.

Is there some option that would allow me to minify those files on compile or publish (other than writing build events to minify those files using external tools).

like image 217
jahu Avatar asked Oct 14 '15 08:10

jahu


1 Answers

The following pertains to VS2015, which has much better support for this scenario.

VS2015 introduces support for task runners like gulp or grunt. You could use one of those, and have a task triggered on project open (i.e. always runs while you're working on the project) which will itself monitor for file changes and run the minimizer (i.e. do it on save).

An intro to gulp in VS2015 is available here.

A simpler alternative on VS2015 is to use the Web Compiler Extension, which basically does the above automagically with less work on your side to set it up.

like image 147
Jimmy Avatar answered Oct 13 '22 11:10

Jimmy