繁体   English   中英

使用和使用打字稿npm模块

[英]using and consuming typescript npm modules

所以我想用打字稿写共享代码,制作一个npm包并能够安装它。

所以我试着这样写一个外部库:

export class Lib {
   constructor(){

   }

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

}

在外部lib上运行npm链接

并在使用的应用程序目录中运行npm链接“ 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'

我可以将其与https://github.com/basarat/ts-npm-module-consume一起使用,但这会产生看起来像这样的输出

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

这对我没有意义,因为我想要一个可以包含在index.html中的.js文件

有任何想法吗?

您是否尝试过使用declare而不是导出?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM