How to use webgrease?

WebGrease is an assembly found in mvc4, but can it be used as Yahoo.Yui.Compressor? I want to use webgrease.dll in a C # console program and compress javascript string for another.

class Program { static void Main(string[] args) { Yahoo.Yui.Compressor.JavaScriptCompressor c = new Yahoo.Yui.Compressor.JavaScriptCompressor(); string s = "function hello (name) { return 'hello '+ name + '!'; }"; s = c.Compress(s); Console.WriteLine(s); } } 
+6
source share
2 answers

It is possible and quite easy. You can find WG.EXE in the Visual Studio folder. WG.EXE is actually a minifier command line that invokes the same minimization libraries. You can use it from the command line or from MSBuild or any of the script of your choice to perform the minimization.

Here is a good article written by the WG group on how to use WG from the command line: http://kenhaines.net/post/2012/06/09/WebGrease-As-seen-in-Visual-Studio-2012.aspx

you can also check https://webgrease.codeplex.com/documentation

for details

+8
source

It should be possible - when you enable webgrease using NuGet, you also get the β€œWG” command line tool, which does exactly what you are trying to accomplish above. Code for the webgrease dll and WG utilities are available on CodePlex . There are no specific ASP.Net DLL references.

If you have ILSpy or Reflector, see the code for "WebGrease.Program.ProcessJsFileSet" for how to compress Javascript. The WebGrease.Activities.MinifyJSActivity class is the one you need to use, and you can also see it on CodePlex.

+1
source

All Articles