如何在 VSCode 中的 TypeScript 构建期间忽略 `node_modules` 文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30313805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to ignore `node_modules` folder during TypeScript build in VSCode
提问by MonkeyBonkey
I'm using visual studio code IDE and typescript, how do I get it to ignore the node_modules folder during build? Or have it build .ts
files on save? It is showing a lot of errors because it's trying to compile node_modules tsd.
我正在使用 Visual Studio 代码 IDE 和打字稿,如何让它在构建过程中忽略 node_modules 文件夹?或者它.ts
在保存时构建文件?它显示了很多错误,因为它正在尝试编译 node_modules tsd。
Currently my tasks.json is
目前我的tasks.json是
{
"version": "0.1.0",
// The command is tsc.
"command": "tsc",
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// Under windows use tsc.exe. This ensures we don't need a shell.
"windows": {
"command": "tsc.exe"
},
"isShellCommand": true,
// args is the HelloWorld program to compile.
"args": [],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}
采纳答案by Carbosound1
You can now use exclude
in your tsconfig.json file:
您现在可以exclude
在 tsconfig.json 文件中使用:
{
"exclude": [
"node_modules",
],
"compilerOptions": {
...
}
}
https://github.com/Microsoft/TypeScript/wiki/tsconfig.json
https://github.com/Microsoft/TypeScript/wiki/tsconfig.json
Note it's a sibling to, not child of, compilerOptions.
请注意,它是 compilerOptions 的同级,而不是其子级。
回答by Martin M?hnen
In Version 0.5 you can hide files and folders
在 0.5 版中,您可以隐藏文件和文件夹
Open Files->Preferences->User Settingsand add something like
打开文件->首选项->用户设置并添加类似
{
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"jspm_packages" : true,
"node_modules" : true
}
}
回答by Fenton
If you don't supply a files
list, VSCode will compile everything.
如果您不提供files
列表,VSCode 将编译所有内容。
{
"compilerOptions": {
"target": "ES5"
}
}
You can change this by supplying a list of the files you want compiled, e.g:
您可以通过提供要编译的文件列表来更改此设置,例如:
{
"compilerOptions": {
"target": "ES6"
},
"files": [
"app.ts",
"other.ts",
"more.ts"
]
}
回答by httpete
Here is a way to get you by, don't use tsconfig.json for now it doesn't support excludes which you will need. What I want is simply to compile the file you are on with options using tasks.json. For now you have to CTRL+SHIFT+B to build, there is no nice way to build upon saving yet.
这是一种让您度过难关的方法,现在不要使用 tsconfig.json 它不支持排除您需要的内容。我想要的只是使用 tasks.json 使用选项编译您所在的文件。现在你必须 CTRL+SHIFT+B 来构建,还没有好的方法可以在保存时进行构建。
{
"version": "0.1.0",
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "tsc",
// The command is a shell script
"isShellCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "always",
// args is the HelloWorld program to compile.
"args": ["${file}", "--module", "amd", "--target", "ES5"],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}