[TypeScript] Loading Compiled TypeScript Files in Browser with SYSTEMJS

Source: Internet
Author: User
Tags export class

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.