TypeScript outputs JavaScript, but what is supposed to do with it? This lesson shows how to take the output and use SYSTEMJS as the module loader so it can use the files in your brows Er.
To use System.js, first create a index.html, add system.js file from Npmcdn:
HTTPS://npmcdn.com/[email protected]/
Index.html:
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Title</title> <Scriptsrc= "Https://npmcdn.com/[email protected]/dist/system.js"></Script></Head><Body><Script>System.config ({packages: {"Dist": { "defaultextension": "JS", "Main": "Main" } } }); System.import ("Dist")</Script></Body></HTML>
It tell System to load the packages. Serve "Dist" folder, use default extension as JS, and the main entry file is Main.js. Then Import Dist folder.
Start a server:
http-server-c-1 // -c-1-No cache
Run:
TSC-W
To prove it does work on broswer, add console log in the code:
// main.ts './two '; class person{ constructor () { console.log ("person!" ); }} New both (); New Person (); // tow.ts Export Class two{ constructor () { Console.log ("both");} }
[TypeScript] Loading Compiled TypeScript Files in Browser with SYSTEMJS