define(["require", "exports", "js/models/home","templates/home/home.html"
], function(require, exports, __model__, __homeView__) {
var model = __model__;
var homeView=__homeView__;
}
I would like to write a .ts
file which will generate a js
file like this.
By compiling --module
amd I can import a model and also reference the jquery
, backboneJs
or any other js
files.
But how can I import an externer html
file as like requireJs
does?
A module can be created using the keyword export and a module can be used in another module using the keyword import . In TypeScript, files containing a top-level export or import are considered modules.
In TypeScript, just as in ECMAScript 2015, any file containing a top-level import or export is considered a module. Conversely, a file without any top-level import or export declarations is treated as a script whose contents are available in the global scope (and therefore to modules as well).
To include the Require. js file, you need to add the script tag in the html file. Within the script tag, add the data-main attribute to load the module. This can be taken as the main entry point to your application.
I put together a blog a while ago on require.js and Typescript.
http://blorkfish.wordpress.com/2012/10/23/typescript-organizing-your-code-with-amd-modules-and-require-js/
In order to import text files, you will need to reference text.js, and then use the text!<...your text file> syntax, as below. Using the require.config further simplifies the use of require:
require.config({
baseUrl: '../',
paths: {
views: 'app/views',
'text': 'lib/text',
}
});
require([
'text!views/MTodoCollectionView.html'],
(MTodoCollectionViewSnippet) => {
//
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With