问题
First the background - I'm using Handlebars for templating HTML and I want to make use of the bundling and caching capabilities of ASP.NET Bundling to deliver the templates to the client. To that end I've created my own Bundle
subclass and an implementation of IBundleTransform
that does some necessary conversion of my templates. In particular I:
- add the templates to visual studio as HTML but embed the template in a
<script type='text/x-handlebars-template'>...</script>
which seems to give me great template/html intellisense - in my implementation of
IBundleTransform
I wrap the final template in something along the lines ofInjector.register('{0}', function() {{ return window.atob('{1}'); }});
where{0}
is replaced with the path of the template and is used to fetch the template in client code and{1}
is replaced with a base64 encoded form of the HTML (until I can figure out a better way of encoding the html string!)
My problem comes if I set BundleTable.EnableOptimizations = false
at which point none of number 2 above occurs and I'm delivered the raw file. I've temporarily resorted to the following code which stops minification of all files but still transforms them :
BundleTable.EnableOptimizations = true;
if (System.Diagnostics.Debugger.IsAttached)
{
foreach (var bundle in bundles)
{
if (bundle.Path != "~/bundles/handlebars-templates")
bundle.Transforms.Clear();
}
}
Is there a better option that allows me to turn optimizations off, deliver all my templates individually to the browser but still have them transformed before they go?
来源:https://stackoverflow.com/questions/28632692/how-can-i-still-run-a-custom-ibundletransform-when-enableoptimization-is-off-in