Compiling TypeScript with Cordova™ in Visual Studio® 2015

By default, it seems TypeScript files do not get compiled into JavaScript® if you add them to an Apache Cordova™ based app in Visual Studio® 2015.

Update: This is so only if you select the Cordova app project type in Visual Studio from JavaScript® programming language. If you select it from TypeScript language, the problem doesn’t occur.

However, it’s easy to resolve this once you find aut the steps to perform:

  • Place your TypeScript source code file(s) in the root Scripts folder of the project (not in www/scripts):

  • Add a tsconfig.json file to the Scripts folder indicating which are your TS files and which should be the output JS file (combining all TS output):
    {
       "compilerOptions": { "out": "./www/scripts/app.js" },
       "files": [ "app.ts" ]
    }
    
  • Rebuild the project. Your app.js output file will be generated in www/scripts folder and you can reference it from your index.html now as usual!
Advertisements

About Sorin Dolha

My passion is software development, but I also like physics.
This entry was posted in JavaScript. Bookmark the permalink.

One Response to Compiling TypeScript with Cordova™ in Visual Studio® 2015

Add a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s