This project has moved and is read-only. For the latest updates, please go here.

Question regarding custom Translator/Compiler

Apr 11, 2013 at 7:02 PM
Edited Apr 11, 2013 at 7:38 PM
First off, thanks for writing this excellent library! So far I have been really enjoying working with it and extending it.

So to start off, allow me to explain my situation. I have a fairly JS heavy application that utilizes a lot of Html Templates (handlebars templates to be exact). Now I was using Cassette in the past, but I ran into a lot of problems with that in production, hence giving BT a shot.

Now here's my problem... Since BundleTransformer does not support HtmlTemplates out of the box, I have written my own HandlebarsAssetHandler/Compiler/Translator to take care of this. Everything is working fine when I this use alone, but if I try to enforce other bundles to use a "new JsTransformer" transform, they all seem to want to use my new Handlebars Translator instead. Obviously this causes lots of problems.

Any idea why this could be happening?

If you check out my gist, you can see exactly what I have in place.

Thanks so much for taking the time to make such a great lib!
Apr 12, 2013 at 10:57 AM
Hello, Jaysche!

Update the BundleTransformer.Core to version 1.7.3 Beta 1.

In the HandlebarsCompiler.cs file replace the content of lines 103-111 by following code:
var assetsToProcessing = assets.Where(a => a.AssetType == AssetType.Handlebars).ToList();
if (assetsToProcessing.Count == 0)
    return assets;
using (var handlebarsCompiler = new HandlebarsCompiler()) {
    foreach (var asset in assetsToProcessing) {
        InnerTranslate(asset, handlebarsCompiler);
If the HandlebarsCompiler class does not produce the native minification of JS code, then in the HandlebarsTranslator class you just need to implement the ITranslator interface. If the HandlebarsCompiler class supports native minification, then you must correctly process following properties: NativeMinificationEnabled of the TranslatorWithNativeMinificationBase class and Minified of the IAsset interface (see the example of TypeScriptTranslator.cs).

P.S.: Bundle Transformer cannot be used together with the StyleBundle and ScriptBundle classes, because these classes already contain transformations (instances of the built-in minifiers: CssMinify and JsMinify). Use a Bundle class.
Apr 12, 2013 at 4:47 PM
Hi Taritsyn!

Once again, thanks so much for the super-quick responses. Loving it!

Ahh, okay, I had seen many examples of its usage throughout BundleTransformer, but I wasn't 100% sure if implementing ITranslator was the best course of action. That makes perfect sense, though.

And as for not using the StyleBundle or ScriptBundle classes, I honestly had no idea, haha. I must've totally skipped over that in your documentation. My bad!

Thanks again!