publishing a typescript library on npm: exported symbols, modules

柔情痞子 提交于 2019-12-23 16:14:21

问题


I'm writing a typescript library which I intend to publish on npm. It is meant to run in node only, never in the browser. It will make sense to use the library only from typescript (I'm not expecting any Javascript users).

I have trouble finding guides how to publish typescript-for-typescript libraries on npm (also, these things seem to be changing rapidly in the typescript world).

Should I wrap all my code in a module? (I don't feel the need for modules in the library itself, it's currently only at around 1000 LOC). Should I create an index.ts file? I think I should ship .js, .js.map and .d.ts files but no .ts files for the npm package?

How do i call functions between files in the library without exporting them to users of the library? I currently don't use typescript modules. I tried using typedoc and it lists also symbols that I exported from individual files for the purpose of using in another file of the library. But I don't want these to be visible to the users of library.

Is there a library I could use as an example? I looked at typescript-collections, they don't use any module and have an index.ts. I think they export all their shared functions, so that doesn't help me with that issue.


回答1:


What I did was having the index.ts export all files.

like

export { default as Actions } from './Actions'

then, in you package.json, add property "typings": "dist/index.d.ts" (change the location accordingly)

and yes, export definitions and source-maps. others can use source-map-support package to debug it easily later on.

I prefer pre-build them into .js when publishing.




回答2:


I'd suggest you to take a look at TypeScript Library Starter. It configures out of the box:

  • Package.json configuration
  • Universal module bundles
  • Source Maps
  • Typings (.d.ts)
  • Docs using TypeDoc
  • Tests and coverage


来源:https://stackoverflow.com/questions/41372014/publishing-a-typescript-library-on-npm-exported-symbols-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!