Friday, September 19, 2014

Have Web Essentials make minified JavaScript files from your .js files and keep them up to date.

Here is an example. I made a file called Whatever.js which had this in it:

var whatever = "hello";
var somethingMore = whatever + " world";
alert(somethingMore);

 
 

In the Solution Explorer in Visual Studio 2013, I right-clicked upon the file I made and then picked from the menu which appeared: Web Essentials > Minify JavaScript file(s)

 
 

var whatever="hello",somethingMore=whatever+" world";alert(somethingMore);
/*
//# sourceMappingURL=Whatever.min.js.map
*/

...ended up in a Whatever.min.js file and a Whatever.min.js.map file was also created to associate the Whatever.js file with the Whatever.min.js file. Now whenever I alter and save the Whatever.js file the Whatever.min.js file updates.

 
 

var whatever = "hello";
var somethingMore = whatever + " Mars!";
alert(somethingMore);

...this change to Whatever.js for example creates this change at Whatever.min.js:

 
 

var whatever="hello",somethingMore=whatever+" Mars!";alert(somethingMore);
/*
//# sourceMappingURL=Whatever.min.js.map
*/

No comments:

Post a Comment