码迷,mamicode.com
首页 > 其他好文 > 详细

[TypeScript] Using Typings and Loading From node_modules

时间:2016-06-10 06:14:08      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

Using TypeScript when installing packages from npm often requires you to install related definition files. This lesson shows you how to use typings to install es6-shim then how to configure SystemJS to load from node_modules.

 

Install:

npm install --save rxjs

 

Import:

import {Observable} from ‘rxjs/Observable‘;
import ‘rxjs/add/observable/interval‘;

But you will find errors, the reason for that rxjs include es6, but our target is es5.

 

So, install:

typings install es6-shim --save -ambient

 

Include:

<script>
    System.config({
        packages: {
            "dist": {
                "defaultExtension": "js",
                "main": "main"
            },
            "rxjs": {
                "defaultExtension": "js"
            }
        },
        map: {
            "lodash": "https://npmcdn.com/lodash@4.13.1",
            "rxjs": "node_modules"
        }
    });

    System.import("dist")
</script>

 

Then you can start using rxjs;

import {Observable} from ‘rxjs/Observable‘;
import ‘rxjs/add/observable/interval‘;

Observable.interval(1000)
    .subscribe( x => console.log(x))

 

[TypeScript] Using Typings and Loading From node_modules

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5573085.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!