I am building a Backbone app in TypeScript and I would like to put my templates in separate .html files (for syntax etc). I don't use Require.js now, how can I load text files then. I guess I have to write a function for that, but is there something already available in TypeScript?
3 Answers
With the typescript compiler you can only compile Typescript files. Keeping your code in html files won't allow you to compile code.
If you want to load code from other Typescript files, the compiler currently supports commonjs and amd style imports of modules. You can tell the compiler which type of model to use by specifying tsc --module commonjs or tsc --module amd.
Typescript supports two different kinds of modules, namely external and internal modules. Depending on what type of module you use, importing it works differently. Take a look at section 9 of the language specification and this or this answer.
Comments
There's a requirejs plugin for loading non-code dependencies, in this case, some templates stored in separate html files.
Comments
Someone wrote something similar at https://github.com/iammerrick/require-ts, though you will probably need to adapt it for your needs.