Feature Request: Raw text bundles

Apr 2, 2014 at 4:02 PM
I would like to make a feature request: the ability to add raw text into bundle for CSS or JS. Currently the Include function will only go to get a file from the file system.

An example use case is when your retrieve CSS from a database (maybe for a multi-tenant application) and that gets injected into the bundle. I can see this being useful for injecting LESS variables and value into bundles after getting the values from somewhere other than a text file in the file system.
Coordinator
Apr 2, 2014 at 5:19 PM
Hello, Kdmtx!
I would like to make a feature request: the ability to add raw text into bundle for CSS or JS. Currently the Include function will only go to get a file from the file system.
This functionality is determined at level of the Microsoft ASP.NET Web Optimization Framework. Bundle Transformer is responsible only for transformations. I recommend you to send feature request to this address - https://aspnetoptimization.codeplex.com/workitem/list/basic
An example use case is when your retrieve CSS from a database (maybe for a multi-tenant application) and that gets injected into the bundle.
I recommend you to explore opportunities of the BundleTable.VirtualPathProvider property and read «ASP.NET Bundling/Minification and Embedded Resources» article.
I can see this being useful for injecting LESS variables and value into bundles after getting the values from somewhere other than a text file in the file system.
Look a properties GlobalVariables and ModifyVariables of LESS-translator:
namespace TestBootstrap3
{
    using System.Collections.Generic;
    using System.Web.Optimization;

    using BundleTransformer.Core.Builders;
    using BundleTransformer.Core.Orderers;
    using BundleTransformer.Core.Transformers;
    using BundleTransformer.Core.Translators;
    using BundleTransformer.Less.Translators;

    public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            var nullBuilder = new NullBuilder();
            var nullOrderer = new NullOrderer();

            var lessTranslator = new LessTranslator
            {
                GlobalVariables = "my-variable='Hurrah!'",
                ModifyVariables = "font-family-base='Comic Sans MS';body-bg=lime;font-size-h1=50px"
            };
            var cssTransformer = new CssTransformer(new List<ITranslator>{ lessTranslator });

            var commonStylesBundle = new Bundle("~/Bundles/BootstrapStyles");
            commonStylesBundle.Include(
               "~/Content/less/bootstrap-3.1.0/bootstrap.less");
            commonStylesBundle.Builder = nullBuilder;
            commonStylesBundle.Transforms.Add(cssTransformer);
            commonStylesBundle.Orderer = nullOrderer;

            bundles.Add(commonStylesBundle);
        }
    }
}