繁体   English   中英

如何排除 typescript 中的特定文件仅用于构建?

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

是否可以仅为构建排除所有测试文件,但将它们与 nodemon 一起使用在本地运行测试? 当我在tsconfig.json文件中排除测试文件时,我得到一个 typescript 错误,在我的例子中它找不到像 jest 这样的测试库的类型。

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"
  ]
}

我想知道,因为我猜临时转译被放到了构建文件夹之外的另一个文件夹中。

一种可能的解决方案是使用两个不同的 tsconfig 文件,一个用于测试,一个用于生产构建。

tsconfig.json

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

tsconfig.prod.json

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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