Creating a single CommonJS module from several TypeScript classes

后端 未结 2 478
暖寄归人
暖寄归人 2021-02-08 03:21

I\'m trying to work out the best way to split my application into a few CommonJS modules that can be consumed by other applications.

I have 5 TS classes, and I\'d like t

2条回答
  •  梦谈多话
    2021-02-08 03:48

    Having a separate CommonJS module per file is completely appropriate. All the require calls in TypeScript will translate to CommonJS require calls in JavaScript, and the .d.ts files will be picked up in the process. (If you're doing something silly like requireing classes outside your source directory... stop.)

    You would only need to consider a packaging step if you intended to use this NPM package in other applications, in which case look into Browserify

提交回复
热议问题