Languages
[Edit]
EN

TypeScript - create common project used by multiple projects (works only in web browser)

4 points
Created by:
Palus-Bear
1016

In this article, we would like to show how to create common project that is used by multiple projects using TypeScript.

In the article, presented solution do not compile common project as separated *.js bundle. It compiles all used *.js files into each project output *.js bundles.

Hint: to know how to use compiled files in the web browser check this article.

 

Projects structure

Edit
Common project used by multiple projects created with TypeScript.
Common project used by multiple projects created with TypeScript.

Note: it is good to add Path Autocomplete plugin to get better intellisende with common code inside projects when we use VS Code.

 

Root directory

Edit

package.json file:

 

Common project

Edit

src/printer.ts file:

 

tsconfig.json file:

Hint: this configuration is used only to force source code checking by IDE in common project in src/ and tests/ directories.

 

Project 1

Edit

src/index.ts file:

Hint: to compile source code use npm run project_1:compile command.

 

tsconfig.json file:

 

Project 2

Edit

src/index.ts file:

Hint: to compile source code use npm run project_2:compile command.

 

tsconfig.json file:

 

See also

Edit
  1. TypeScript - compile all ts files to one js

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join