使用和使用typescript npm模块

时间:2016-09-19 14:28:34

标签: javascript typescript npm

所以我想在typescript中编写共享代码,制作一个npm包并能够安装它..

所以我尝试编写这样的外部库:

export class Lib {
   constructor(){

   }

   getData(){
      console.log('getting data from lib');
   }

}

在外部lib上运行npm链接

运行npm link" package"在消费应用程序目录中,让它出现在它的node_modules

consuming-app
   index.ts
   node_modules/ 
       external-package-with-typescript

index.ts很简单,它看起来像:

import { Lib } from 'external-package-with-typescript'

var l = new Lib();

然后我尝试用

捆绑所有内容
browser index.ts -p tsify --global --debug > bundle.js

这会导致外部包

出错
'import' and 'export' may appear only with 'sourceType: module'

我可以使用ActiveRecord::QueryMethods#distinct 但是这会产生类似于

的输出
consuming-app/ index.ts
external-package-with-typescript/ index.ts

这对我来说没什么价值,因为我想要一个我可以包含在index.html中的.js文件

想点什么?

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用declare代替导出?