Bundle Transformer: TypeScript
BundleTransformer.TypeScript contains translator-adapterTypeScriptTranslator (supports
TypeScript version 1.5.0 Beta). This adapter makes translation of TypeScript-code to JS-code. Also contains HTTP-handlerTypeScriptAssetHandler, which is responsible for text output of translated TypeScript-asset.
BundleTransformer.TypeScript does not support external modules (CommonJS and AMD modules).
As a JS-engine is used the
JavaScript Engine Switcher library. For correct working of this module is recommended to install one of the following NuGet packages:
JavaScriptEngineSwitcher.Msie or
JavaScriptEngineSwitcher.V8. After package is installed, need set a name of JavaScript engine (for example,MsieJsEngine) to the
name attribute of /configuration/bundleTransformer/typeScript/jsEngine configuration element.
To use a debugging HTTP-handler in the IIS Classic mode, you need add to the
/configuration/system.web/httpHandlers element of the
Web.config file a following code:
<addpath="*.ts"verb="GET"type="BundleTransformer.TypeScript.HttpHandlers.TypeScriptAssetHandler, BundleTransformer.TypeScript"/>
When using the types declared in other files, you need add to code the references to these files by using the "reference" comments, as shown in the following example:
/// <reference path="./jquery.d.ts" />/// <reference path="./ITranslatorBadge.d.ts" />
module TranslatorBadges {
export class TranslatorBadge implements ITranslatorBadge {
…
}
}
If you are add TypeScript-files to the bundle by using the
IncludeDirectory method, then I recommend you to use instance of the
ScriptDependencyOrderer class from the
Arraybracket.Bundling project as a bundle orderer:
namespace BundleTransformer.Example.Mvc
{
…
using Arraybracket.Bundling;…
publicclass BundleConfig
{
publicstaticvoid RegisterBundles(BundleCollection bundles)
{
…
var tsBundle = new Bundle("~/Bundles/TypeScripts");
tsBundle.IncludeDirectory("~/Scripts/ts/", "*.ts", true);
tsBundle.Builder = nullBuilder;
tsBundle.Transforms.Add(new ScriptTransformer(new []{ "*.d.ts" }));
tsBundle.Orderer = newScriptDependencyOrderer();
bundles.Add(tsBundle);
…
}
}
}
This will allow to properly sort TypeScript-files in the bundle (on the basis of information, that obtained from the "reference" comments).