WG.exe (WebGrease) 1.6.0

WebGrease optimizes a web application’s static files, including CSS, JavaScript, and image files. It includes the following capabilities:

  • Minimize CSS and JavaScript files
  • Bundle all static files into a single output file
  • Combine all images referenced in a CSS file into a single sprite
  • Verify JavaScript files
  • Rename static files based on a hash of their content

WebGrease can be run completely from the command line, or you can specify a WebGrease configuration file that contains the settings. WebGrease also includes a WebGrease build task that can be integrated with an MSBuild project.

This tool is automatically installed with Visual Studio. To run the tool, we recommend that you use the Visual Studio Command Prompt. This utility enables you to run the tool easily, without navigating to the installation folder. For more information, see Visual Studio and Windows SDK Command Prompts.

  • On the taskbar, click Start, click All Programs, click Visual Studio, click Visual Studio Tools, and then click Visual Studio Command Prompt.
  • At the command prompt, type the following:
    wg options
 For a list of planned features, please see the Roadmap.

Syntax

wg {-a | -b | -m | -s | -v} [-c:<filename>] [-images:<path>] [-log:<path>] [-tokens:<path>] [-type:<config type>] [-in:<location or base path>] [-out:<location or base path>]

Options

You can specify some of the following options:

Option Description

-a

Renames the input files based on a hash of their content and creates an XML lookup file that contains a mapping of the original names to the new names. This option cannot be used with -b, -m, -s, or -v.

-b

Bundles all input files into a single output file. Required if the -out option specifies a file. This option cannot be used with -a, -m, -s, or -v.

-c:filename and path

Specifies a WebGrease configuration file. The path can be relative or absolute.

-images:path

Specifies the folder that contains the images to be combined into a sprite. The path can be relative or absolute. Required if the -s option is used.

-in:filename, path, or base path

Specifies the location of the input file(s) or the base input path. If you specify a single file, only that file is processed. If you specify a folder, all files in the folder are processed. If the –c option is used, this value specifies the base path of all input paths within the configuration file. In all cases, the path can be relative or absolute. The default is the current directory.

-log:path

Specifies the directory for the log file. The path can be relative or absolute. The default is the current directory.

-m

Minimizes the file(s) specified by the –in option. This option cannot be used with -a, -b, -s, or -v.

-out:filename, path, or base path

Specifies the location of the output file(s) or the base output path. If the –in option specifies a folder, this value must also specify a folder unless the –b option is used. If the –c option is used, this value specifies the base path of all output paths within the configuration file. In all cases, the path can be relative or absolute. The default is the current directory.

-s

Combines all images referenced in the CSS file into a sprite and creates a new version of the CSS file that references the sprite for all images. All images must be in the path specified by the –images option. This option cannot be used with -a, -b, -m, or -v.

-tokens:path

Specifies the directory for the tokens file. The path can be relative or absolute.

-type:solution configuration name

Specifies the solution configuration name. This value is case-sensitive. If this is not used, the first solution configuration found in the WebGrease configuration file is used. Must be used with the –c option.

-v

Validates the JavaScript file(s) and outputs the results to the console.

 Note: Only one of the following options can be used: -a, -b, -m, -s, or -v.

Remarks

WG.exe can only run one operation per execution. Most users will likely call WG.exe repeatedly from a build script to execute multiple operations.

One of the following mutually-exclusive options must be specified on the command line: -a, -b, -m, -s, or -v.

You can use the –c option to specify a WebGrease configuration file. The configuration file supports additional options that are not available on the command line and it allows you to preconfigure the settings for various operations. For a complete description, see WebGrease configuration file.

All paths can be relative or absolute. The default value for all paths is the current directory.

Examples

The following command minimizes a single CSS file:

wg -m -in:.\sample.css -out:.\sample.min.css
 

The following command minimizes all CSS and JavaScript files in a folder:

wg -m -in:C:\mystaticfiles -out:C:\minified
 

The following command validates all JavaScript files in a folder:

wg -v -in:.\myjs\
 

The following command bundles all JavaScript files in a folder into a single file:

wg -b -in:C:\javascript -out:bigjavascriptfile.js
 

The following command renames the input files using the settings in a WebGrease configuration file:

wg -a -c:sample.config -in:C:\www\content -out:C:\www\crunched\ -t:Release
 

See Also

Last edited Apr 18, 2014 at 5:51 PM by smackin, version 7

Comments

rumzeus Dec 1, 2014 at 10:29 AM 
"This tool is automatically installed with Visual Studio."
I don't see it in my VS 2010 or 2013 installation. Please clarify.

jawandarajbir Oct 27, 2014 at 1:07 AM 
Hi, I'm getting System.IO.FileNotFoundException when using WebGrease 1.6 via Developer Command Prompt for VS2013. More details here - https://webgrease.codeplex.com/workitem/38

I'm using:
- WebGrease.1.6.0
- Visual Studio 2013 Update 3
- Windows 8.1 (64 bit)

What am I missing? Any help solving this issue is much appreciated.