How to use webgrease?
Asked Answered
R

2

9

WebGrease is an assembly found in mvc4, but can it be used like Yahoo.Yui.Compressor? I want to use webgrease.dll in a C# console programe and compress a javascript string to 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);
        }
    }
Reddick answered 21/2, 2014 at 4:20 Comment(0)
S
14

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

Here is a good article written by WG team on how to use WG from command line: https://kenhaines.net/webgrease-as-seen-in-visual-studio-2012/

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

for detail information

Slow answered 20/3, 2014 at 6:57 Comment(0)
S
2

It should be possible - when you include webgrease using NuGet, you also get the "WG" command line tool that does exactly what you are trying to accomplish above. Code for the webgrease dll and the WG utility are available on CodePlex. There are no specific ASP.Net dll references in it.

If you have ILSpy or Reflector have a look in the code for "WebGrease.Program.ProcessJsFileSet" for how to compress Javascript. The class WebGrease.Activities.MinifyJSActivity is the one to use, and you can see that one on CodePlex as well.

Sabin answered 21/2, 2014 at 5:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.