简体   繁体   中英

How to exclude specific files in typescript only for the build?

Is it possible to exclude all test files only for the build but use them with nodemon to run tests locally? When I exclude test files within the tsconfig.json file I get a typescript error that it can't find the types of the testing library like jest in my case.

Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.ts(2582)

{
  "compilerOptions": {},
  "exclude": [
    "**/*.test.ts"
  ]
}

I am wondering since I guess the temporary transpiling is put into another folder than the build folder.

One possible solution would be to use two different tsconfig files, one for the tests and one for the production build.

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "outDir": "./build",
    "baseUrl": ".",
    "paths": {
      "*": ["types/*"]
    },
    "strict": true,
  }
}

tsconfig.prod.json

{
  "extends": "./tsconfig",
  "exclude": ["**/*.test.ts", "**/*.mock.ts"]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM