请问 tsconfig.json 是否需要排除 node_modules 文件夹,比如
{
"include": ["src/**/*"],
"exclude": [
"node_modules"
]
}
exclude
默认值是 ["node_modules", "bower_components", "jspm_packages"]
,如果 tsconfig.json 中没有设置 exclude
,则默认会被排除。
如果 tsconfig.json 中设置了 exclude
,会覆盖默认值,就需要 exclude
中包含 "node_modules"
。
参考:
1)https://www.typescriptlang.org/tsconfig#exclude
It is not a mechanism that prevents a file from being included in the codebase - it simply changes what the include setting finds.
2)https://typescript-v2-140.ortam.vercel.app/docs/handbook/tsconfig-json.html#details
Files included using "include" can be filtered using the "exclude" property. However, files included explicitly using the "files" property are always included regardless of "exclude". The "exclude" property defaults to excluding the node_modules, bower_components, jspm_packages and <outDir> directories when not specified.
3)https://stackoverflow.com/a/68579788
Since it is recommended to always exclude node_modules, TypeScript decided to add it as a default value. You can therefore omit the whole exclude specification if you only want to exclude node_modules.
Since you also want to exclude *.spec.ts files (not default), you need to specify it the way you did.
如果 include
指定的路径中不会包含 node_modules
,则不需要 exclude