打字稿创建模块 [英] Typescript creating modules
本文介绍了打字稿创建模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为我们的库中创建模块,所以每次我们打电话的时候,我们可以使用 {进口的API,地图}从ourlibrary
目前我使用的是以下内容。
进口{}阿比从../../Library/Api
进口{} MapPage从../map/map
我如何创建我自己的包得到下面的结果?
从OurLib进口{的API,地图}
解决方案
我看到两个步骤来做到这一点:
-
创建了
地图中的条目
您SystemJS配置块:System.config({
图:{
OurLib':'路径到ourlib
},
包:{
OurLib:{
主:'index.js',
defaultExtension:'JS'
}
}
}); -
为切入点模块,导入你想使你的可用库外什么/导出创建打字稿文件(例如,
index.ts
){出口阿比}从../../Library/Api
出口{} MapPage从../map/map
I wanted to create modules for our library, so each time we call, we can use import {Api, Map} from "ourlibrary"
currently I'm using following.
import {Api} from "../../Library/Api";
import {MapPage} from "../map/map";
How I can create my own packages to get following result?
import {Api, Map} from "OurLib"
解决方案
I see two steps to do that:
Create an entry in the
map
block of your SystemJS configuration:System.config({ map: { 'OurLib': 'path-to-ourlib' }, packages: { 'OurLib': { main: 'index.js', defaultExtension: 'js' } } });
Create a TypeScript file (for example,
index.ts
) as entry point module that import / export what you want to make available outside your library:export {Api} from "../../Library/Api"; export {MapPage} from "../map/map";
这篇关于打字稿创建模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文