Skip to content

JamieDixon/Web.Optimization

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Web.Optimization

Web.Optimization allows you to transform LESS and CoffeeScript files by making use of the upcoming bundling and minification features.

Installation

Usage - Bundles (CoffeeScript, LESS & SASS/SCSS)

protected void Application_Start()
{
	// ...
	
	// Register CoffeeScript files
	
	var scripts = new Bundle(
        "~/Content/coffee", 
        new CoffeeScriptTransform().Then(new JsMinify()));

	instance.Include(
        "~/Scripts/first.coffee",
        "~/Scripts/second.coffee",
        "~/Scripts/third.coffee");

	BundleTable.Bundles.Add(scripts);
	
	
	// Register LESS files
	
    var styles = new Bundle(
        "~/Content/less",
        new LessTransform().Then(new CssMinify()));
    
	styles.Include(
	    "~/Content/first.less", 
	    "~/Content/second.less", 
	    "~/Content/third.less");

	BundleTable.Bundles.Add(styles);
}

Usage - Configuration

Web.Optimization contains a ConfigurationSection, which allows you to register all your bundles in the web.config:

<configSections>
  <section name="web.optimization" type="Web.Optimization.Configuration.OptimizationSection" />
</configSections>

<web.optimization>
  <bundles>
    <bundle virtualPath="~/Content/js" transform="System.Web.Optimization.JsMinify, System.Web.Optimization">
      <content>
		<!-- Add some single files -->
        <add path="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js" />
        <add path="~/Scripts/forms.js" />
        <add path="~/Scripts/validation.js" />            
		<!-- Add a directory (and its subdirectories) -->
        <add path="~/Content/Scripts/Plugins" searchPattern="*.js" searchSubdirectories="true" />
      </content>
    </bundle>
  </bundles>
</web.optimization>

After the registration is done, you have to tell your application to use these bundles:

protected void Application_Start()
{
  // ...

  BundleTable.Bundles.EnableConfigurationBundles();
}

Usage - Unbundled files for debugging purposes

<head>
  <meta charset="utf-8" />
  <!-- ... -->
  @Html.RenderBundle("~/Content/style")  
</head>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published