如何仅针对构建排除打字稿中的特定文件?
How to exclude specific files in typescript only for the build?
是否可以仅针对构建排除所有测试文件,但将它们与 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"]
}
然后在 运行 tsc -p tsconfig.prod.json
时将 tsc 指向新配置
是否可以仅针对构建排除所有测试文件,但将它们与 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"]
}
然后在 运行 tsc -p tsconfig.prod.json