官术网_书友最值得收藏!

Additions to compiler options

Just referencing another project isn't enough for the TypeScript compiler to properly handle multiple projects. We need to add some additional compiler options in the dependent project.

The compilerOptions field has a new field called composite, which must be set to true if we are using multiple projects. This ensures certain options are enabled so that this project can be referenced and built incrementally for any project that depends on it.

When composite is true, declaration must also be set to true, forcing the corresponding .d.ts file to be generated, containing the project's types. This allows TypeScript to only build dependent projects when types are changed and not rebuild all the dependent projects all the time.

Let's make the following changes to our working example:

  1. Let's open up tsconfig.json in the Shared project and make the following changes:
{
"compilerOptions": {
"composite": true,
"declaration": true,
...
},
}
  1. In the terminal, let's go to the Shared project directory and compile our Shared project:
cd ..
cd Shared
tsc

The project compiles okay. Let's now try to compile ProjectA again in the terminal:

cd ..
cd ProjectA
tsc

   This time, ProjectA compiles just fine.

So, we have successfully tied together two projects using TypeScript 3's multiple projects feature. In the next section, we'll improve the setup of our projects even more.

主站蜘蛛池模板: 东安县| 天祝| 镇江市| 安康市| 丹寨县| 苍梧县| 澄江县| 娱乐| 武清区| 九龙城区| 尖扎县| 墨竹工卡县| 紫阳县| 广汉市| 乡城县| 齐河县| 福泉市| 青岛市| 阜平县| 蕲春县| 维西| 余干县| 韩城市| 保定市| 邵东县| 迁安市| 古丈县| 灌阳县| 昌吉市| 延寿县| 延津县| 榆社县| 灵丘县| 顺平县| 广灵县| 葵青区| 泽库县| 贵南县| 广河县| 乌鲁木齐县| 浦东新区|