Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

typescript - How to handle a project with multiple tsconfig.json files?

I'm working on a project structured like this:


|- built
|- src
|- perf
   |- tsconfig.json
|- typings
|- tsconfig.json

My tsconfig.json on the root

"target": "es6",
"outDir": "built",
"rootDir": "./src",

I need a different configuration on the perf folder, like a different target.

"target": "es5",

However, my typings folder is on the root of my project, not inside perf folder. So doing a tsc ./perf results in a lot of errors.

Is there a way to tell TypeScript where to look for typings? I'm using

npm install -g typescript@next
// [email protected]

Or a way to have different configurations depending on the folder?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you can do this by extending your base tsconfig.json file:

tsconfig extension

just do not exclude directories in the base tsconfig.json and typescript should be able to resolve your typings for you (know this is true using node_modules/@types, or the typings module)

For example:

configs/base.json:

{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true
  }
}

tsconfig.json:

{
  "extends": "./configs/base",
  "files": [
    "main.ts",
    "supplemental.ts"
  ]
}

tsconfig.nostrictnull.json:

{
   "extends": "./tsconfig",
   "compilerOptions": {
     "strictNullChecks": false
   }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
...