0

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 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

There's a requirejs plugin for loading non-code dependencies, in this case, some templates stored in separate html files.

requirejs/text on github

Comments

-1

Someone wrote something similar at https://github.com/iammerrick/require-ts, though you will probably need to adapt it for your needs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.