首页 新闻 会员 周边 捐助

typescript: tsconfig.json 是否需要 exclude node_modules

0
悬赏园豆:30 [已解决问题] 解决于 2023-12-01 12:19

请问 tsconfig.json 是否需要排除 node_modules 文件夹,比如

{
    "include": ["src/**/*"],
    "exclude": [
        "node_modules"
    ]
}
dudu的主页 dudu | 高人七级 | 园豆:29622
提问于:2023-12-01 10:53
< >
分享
最佳答案
0

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.

dudu | 高人七级 |园豆:29622 | 2023-12-01 11:47

如果 include 指定的路径中不会包含 node_modules,则不需要 exclude

dudu | 园豆:29622 (高人七级) | 2023-12-01 12:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册