Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript local dependencies (Multiple Projects)

I am new in typescript. I am currently trying to create a project structure with dependencies to each other. There are three projects core, calculator and tax-calculator. The project tax-calculator needs code from the calculator project, which needs the content from the core project. The core and calculator project should be libraries and the tax-calculator should be an web interface. The reason why i split the code is, that i need the core and calculator in other projects too.

core
    |--src
        |--MathUtils.ts
        |--...
    |--dist
        |--MathUtils.js

calculator
    |--src
        |--Calculator.ts // needs MathUtils.ts
    |--dist
        |--Calculator.js

tax-calculator
    |--src
        |--TaxCalculator.ts // needs Calculator.ts
    |--dist
        |--TaxCalculator.js

How can i provide that the sources are available in the other projects using npm or webpack? I am using VisualStudio Code, i want to use autocomplition and the other features while developing like when i using the @types/chrome or other types.

like image 432
kpalatzky Avatar asked Apr 25 '17 05:04

kpalatzky


1 Answers

Little late to the party, but I will provide different options available as of today, December 2018:

Custom setup using node/shell scripts like done in Cycle.js:

Setting up JavaScript Monorepo.

Using Lerna:

Many big projects including Babel, Marble.js, Material, Angular use Lerna for multi-package setup.

Typescript Project References:

TypeScript 3.0 now provides a support for Project references.

Git submodules

Git submodules can be also used, though it is not just TypeScript. It can be used for sharing any type of code. Ghost blogging platform uses this approach. I would not really recommend this approach unless you know all the issues associated with this.

Also, if you are using Yarn, you can consider workspaces, though I am not sure how well it plays with TypeScript.

like image 146
Harshal Patil Avatar answered Nov 16 '22 06:11

Harshal Patil