javascript - 如何仅在构建中排除打字稿中的特定文件?
问题描述
是否可以仅为构建排除所有测试文件,但将它们与 nodemon 一起使用在本地运行测试?当我在tsconfig.json
文件中排除测试文件时,我收到一个打字稿错误,在我的情况下它找不到测试库的类型,比如 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"]
}
推荐阅读
- c# - 为什么在 .NET 方法注释中使用数字字符引用?
- c - PIE 文件在链接期间是否提供了虚拟内存地址?
- json - 根据 JSON 标准对某些 tableView 行应用复选标记
- android-studio - 如何阻止 AndroidStudio 覆盖 .idea/codeStyles/Project.xml
- python - Python Pandas:如何使用返回 pd.Series 的函数进行分组聚合
- swift - 如何在 segue 期间将数据传递给 2 个或更多 ViewController
- reactjs - 带有 useState 的 Radium 使钩子调用无效
- html - 可以在 HTML 元素中识别角度组件吗?
- flutter - “setState”不适用于图像更新
- roblox - Roblox 错误参数 #2 到“删除”(预期数字,得到字符串)