A lightweight runtime CSS/JavaScript file minification, combination, compression & management library for ASP.Net Core
C# JavaScript Other
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
assets
src
test
.gitignore
LICENSE
Nuget.config
README.md
Smidge.sln
build.ps1
global.json
tests.ps1

README.md

Build status

Smidge Smidge

Smidge 2.0.0-alpha - A lightweight runtime CSS/JavaScript file minification, combination, compression & management library for ASP.Net Core

Install/Configuration

Currently supporting ASP.NET Core 1.0, built against NETStandard.1.6 & .Net Framework 4.5.2

Nuget:

Install-Package Smidge -Pre
//Then register/configure smidge services
services.AddSmidge(/* optional IConfiguration parameter */);

See Installation for full configuration details

Usage

Pre-defined bundles

Define your bundles during startup:

services.UseSmidge(bundles =>
    {
        //Defining using JavaScriptFile's or CssFile's:

        bundles.Create("test-bundle-1", //bundle name
            new JavaScriptFile("~/Js/Bundle1/a1.js"),
            new JavaScriptFile("~/Js/Bundle1/a2.js"));

        //Or defining using file/folder paths:

        bundles.Create("test-bundle-2", WebFileType.Js, 
            "~/Js/Bundle2", "~/Js/OtherFolder*js");

        //Then there's all sorts of options for configuring bundles with regards to customizing their pipelines,
        //customizing how rendering is done based on Debug or Production environments, if you want to 
        //enable file watchers, configure custom cache busters or the cache control options, etc...
        //There's even a fluent API to do this! Example: 

        bundles.Create("test-bundle-3", WebFileType.Js, "~/Js/Bundle3")
            .WithEnvironmentOptions(BundleEnvironmentOptions.Create()
                    .ForDebug(builder => builder
                        .EnableCompositeProcessing()
                        .EnableFileWatcher()
                        .SetCacheBusterType<AppDomainLifetimeCacheBuster>()
                        .CacheControlOptions(enableEtag: false, cacheControlMaxAge: 0))
                    .Build()
            );
    });

If you don't want to create named bundles and just want to declare dependencies individually inside your Views, you can do that too! You can create bundles (named or unnamed) during runtime ... no problem.

See Declarations for full declaration/usage details

Rendering

The easiest way to render bundles is simply by the bundle name:

<script src="my-awesome-js-bundle" type="text/javascript"></script>
<link rel="stylesheet" href="my-cool-css-bundle"/>

This uses Smidge's custom tag helpers to check if the source is a bundle reference and will output the correct bundle URL. You can combine this with environment variables for debug/non-debug modes. Alternatively, you can also use Razor to do the rendering.

See Rendering for full rendering & debug mode details

Custom pre-processing pipeline

It's easy to customize how your files are processed including the way files are minified, how URLs are resolved, etc.... This can be done at a global/default level, at the bundle level or at an individual file level.

See Custom Pre-Processing Pipeline for information about customizing the pre-process pipeline

URLs

There's a couple of methods you can use retrieve the URLs that Smidge will generate when rendering the <link> or <script> html tags. This might be handy in case you need to load in these assets manually (i.e. lazy load scripts, etc...):

Task<IEnumerable<string>> SmidgeHelper.GenerateJsUrlsAsync()
Task<IEnumerable<string>> SmidgeHelper.GenerateCssUrlsAsync()

See Asset URLs for information about retrieving the debug and non-debug asset urls for your bundles

Documentation

All of the documentation lives here

I haven't had time to document all of the features and extensibility points just yet but I'm working on it :)

Copyright & Licence

© 2016 by Shannon Deminick

This is free software and is licensed under the MIT License

Logo image Designed by Freepik