Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

How to use System.Web.Optimization Bundling with Nancy

Thomas Palme edited this page Dec 9, 2013 · 14 revisions

(WARNING: This most likely only works in development and with Optimizations turned off!)

  1. Install the Microsoft.AspNet.Web.Optimization Nuget Package
  2. Setup your bundles in the ApplicationStartup Method of your Bootstraper!
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) 
{
    BundleTable.Bundles.Add(new ScriptBundle().Add(....));
}
  1. Add your respective folders to the StaticContentsConventions in the ConfigureConventions Method of the Bootstraper
protected override void ConfigureConventions(NancyConventions nancyConventions)
{
    base.ConfigureConventions(nancyConventions);
    nancyConventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("/Scripts"));
}
  1. Add System.Web and System.Web.Optimization to your Razor Assemblies:
<razor disableAutoIncludeModelNamespace="false">
        <assemblies>
            <add assembly="System.Web.Optimization" />
            <add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </assemblies>
    </razor>
  1. Don't use @Scripts.Render() but use @Html.Raw(Scripts.Render())

Again, this is not tested with Production(Release), i just use it so i can have a whole directory of my JS files in my Index, and i don't have to add every single js file mannually!

Clone this wiki locally