Documentation

Add Per Sub-Directory

In a large application it's good to separate related assets into directories. Each directory can then be a Cassette bundle.

Here's an example directory structure:

Scripts/
- Dashboard/
  - header.js
  - popup.js
- Widgets/
  - datepicker.js
  - autocomplete.js
- jquery.js
- underscore.js

We can turn this into three bundles using the AddPerSubDirectory method.

public class CassetteConfiguration : IConfiguration<BundleCollection>
{
    public void Configure(BundleCollection bundles, CassetteSettings settings)
    {
        bundles.AddPerSubDirectory<ScriptBundle>("Scripts");
    }
}

A bundle is added for each immediate sub-directory of the given path.

Also, a bundle is created for just top-level assets of the path. This is useful because many third-party nuget packages drop their scripts into ~/Scripts. So it's sensible to move your own scripts into sub-directories.

FileSearch

To control which assets are included in the bundle, use an overload of the AddPerSubDirectory method.

public class CassetteConfiguration : IConfiguration<BundleCollection>
{
    public void Configure(BundleCollection bundles)
    {
        bundles.AddPerSubDirectory<ScriptBundle>("Scripts", new FileSearch
        {
            Pattern = "*.js;*.coffee",
            SearchOption = SearchOption.AllDirectories, // The default
            Exclude = new Regex("-vsdoc\\.js$") // The default
        });
    }
}

Customizing bundles

The Bundle object created by Cassette can be customized by providing an action delegate.

This is useful for changing the pipeline used to process the bundle.

public class CassetteConfiguration : IConfiguration<BundleCollection>
{
    public void Configure(BundleCollection bundles)
    {
        bundles.AddPerSubDirectory<ScriptBundle>(
            "Scripts",
            bundle => bundle.PageLocation = "body"
        );
    }
}