Git Product home page Git Product logo

nancy.bundleit's Introduction

Nancy.BundleIt

A bundling library made for Nancyfx as an alternative to Cassette.

Nancy.BundleIt minifies, obfuscates, concatenates, caches and versions all of your Javascript and CSS files. It uses the well tested and proven Port of Yahoo!'s Java YUICompressor to .NET to minify & obfuscates the code.

If your using BundleIt in a project you would like to share. Send me the url and I'll add it here! DonnyV@Twitter

Features

  • Manage your debug and release versions of your .js and .css files in one place.
  • Minify javascript and css using YUICompressor
  • Override default YUICompressor settings for each file.
  • Bundles files automatically in release mode.
  • Support for CDNs
  • Force release mode or debug mode
  • Force an exception to be thrown when a file is missing.
  • If ".min." is detected in file name, BundleIt will use source as is and not compress it.
  • Works with .NET and Mono.
  • Bundles can be combined to make new bundles. Only need to declare files once!
  • In memory caching for optimal performance.
  • Aggressive HEADER cache settings. Using ETag and Cache-Control. Only download bundle once!

How to install

Just download nuget package. NuGet Version NuGet Downloads

Nuget will drop a class into your project called "BundleItConfig.cs".

using System.Collections.Generic;
using Nancy.BundleIt;

/// <summary>
/// Configures Nancy.BundleIt assets on application startup.
/// There can only be 1 class that uses the interface IBundleItConfig per project. 
/// BundleIt will use the first one it finds.
/// </summary>
public class BundleItConfig : IBundleItConfig
{
	public void Configure(Bundles bundles, ConfigSettings settings)
	{
		// Optional settings
		//settings.ScriptPath = "_scriptbundle";
		//settings.StylePath = "_stylebundle";
		//settings.ThrowExceptionWhenFileMissing = true;
		//settings.ForceDebugMode = false;
		//settings.ForceReleaseMode = true;
		

		// Add scripts based on relative path from project's root.
		var bundleRactive = bundles.AddScripts("ractive", new List<BundleItFile>
		{
			new BundleItFile("app/vendors/ractiveJS/ractive.0.4.0.js", "app/vendors/ractiveJS/ractive.0.4.0.min.js"),
			new BundleItFile("app/vendors/ractiveJS/ractive-transitions-fade.js")
		});

		// You can also add a CDN and use bundles you have already created.
		var bundleBase = bundles.AddScripts("base", new List<BundleItFile>
		{
			new BundleItFile("app/vendors/jquery.1.11.0.js", "//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js", true),
			new BundleItFile(bundleRactive),
			new BundleItFile("app/vendors/lodash.2.4.1.min.js"),
			new BundleItFile("app/common/js/toolbox.js")
		});

		// Add your CSS also
		var base_bundle_css = bundles.AddStyles("base", new List<BundleItFile>
		{
			new BundleItFile("app/common/css/common.css")
		});
	}
}

Remember to add a reference in the "RazorConfig.cs" file.

public class RazorConfig : IRazorConfiguration
{
    public IEnumerable<string> GetAssemblyNames()
    {
        yield return "Nancy.BundleIt";
    }

    public IEnumerable<string> GetDefaultNamespaces()
    {
        yield return "Nancy.BundleIt";
    }

    public bool AutoIncludeModelNamespace
    {
        get { return false; }
    }
}

Then call your bundles in the view.

@using Nancy.BundleIt

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Account Dashboard</title>
    @BundleItAssets.RenderCSS("base")
</head>
<body>
    <b>Account Dashboard</b>
    <!-- content -->
    @BundleItAssets.RenderJS("base")
</body>
</html>

YUI Compressor Notes

It is possible to prevent a local variable, nested function or function argument from being obfuscated by using "hints". A hint is a string that is located at the very beginning of a function body like so:

function fn (arg1, arg2, arg3) {
    "arg2:nomunge, localVar:nomunge, nestedFn:nomunge";

    ...
    var localVar;
    ...

    function nestedFn () {
        ....
    }

    ...
}

The hint itself disappears from the compressed file.

Copyright

Copyright © 2014 Donny Velazquez and contributors

License

Nancy.BundleIt is licensed under MIT.

nancy.bundleit's People

Contributors

donnyv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.