Documentation

Bundle pipelines

Each bundle is assigned a pipeline that is used the process to bundle. A bundle pipeline is a list of steps. These steps perform tasks such as parsing reference comments, sorting assets, minification, etc.

Cassette plug-ins and your application are able to customize pipelines. For example, the Cassette.CoffeeScript will insert a step into ScriptPipeline that compiles .coffee files.

Default bundle pipelines

Cassette provides default bundle pipelines for each type of bundle. In order to customize pipelines it is useful to know the order of the predefined steps.

Script Pipeline

AssignScriptRenderer
ParseJavaScriptReferences
SortAssetsByDependency
AssignHash
ConcatenateAssets (if not debug mode)
MinifyAssets (if not debug mode)

Stylesheet Pipeline

AssignStylesheetRenderer
ParseCssReferences 
ExpandCssUrls
SortAssetsByDependency
AssignHash
ConcatenateAssets (if not debug mode)
MinifyAssets (if not debug mode)

Html Template Pipeline

AssignHtmlTemplateRenderer
ParseHtmlTemplateReferences
WrapHtmlTemplatesInScriptElements
AssignHash
ConcatenateAssets

Modifying bundle pipelines

Cassette provides the Cassette.BundleProcessing.IBundlePipelineModifier<T> interface.

public interface IBundlePipelineModifier<T> where T : Bundle
{
    IBundlePipeline<T> Modify(IBundlePipeline<T> pipeline);
}

During application start-up, Cassette will scan for public classes that implement this interface. When a bundle pipeline is created, Cassette will pass it to each bundle modifier's Modify method. The modifier can alter the pipeline directly and/or return a new pipeline.

Example bundle pipeline modifier

The type attribute on HTML5 <script> elements is optional. So let's modify the pipeline to add a step that removes the type attribute.

First we need to implement a bundle processor that removes the attribute.

public class RemoveScriptTypeAttribute : IBundleProcessor<ScriptBundle>
{
    public void Process(ScriptBundle bundle)
    {
        bundle.HtmlAttributes.Remove("type");
    }
}

Next we insert this processor step into the pipeline.

public class InsertIntoPipelineRemoveScriptTypeAttribute : IBundlePipelineModifier<ScriptBundle>
{
    public IBundlePipeline<T> Modify(IBundlePipeline<T> pipeline)
    {
        // Insert at the beginning of the pipeline (index 0).
        pipeline.Insert<RemoveScriptTypeAttribute>(0);
        return pipeline;
    }
}

We're using an overload of the Insert method that uses the Cassette IoC container to create the given bundle processor type. This is useful when the processor has dependencies passed in via its constructor.

That's it. Cassette will now use the modifier to modify the ScriptPipeline instances it creates.

If your bundle processor needs to appear before or after a particular existing step in the pipeline, then use the pipeline.IndexOf<StepTypeHere>() method to get the index of the existing step.