Как игнорировать папку `node_modules` во время сборки TypeScript в VSCode
Я использую Visual Studio IDE и typescript, как заставить его игнорировать папку node_modules во время сборки? Или создать файл .ts
при сохранении? Он показывает много ошибок, потому что пытается скомпилировать node_modules tsd.
В настоящее время мои задачи .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"
}
Ответы
Ответ 1
Теперь вы можете использовать exclude
в вашем файле tsconfig.json:
{
"exclude": [
"node_modules",
],
"compilerOptions": {
...
}
}
https://github.com/Microsoft/TypeScript/wiki/tsconfig.json
Обратите внимание, что брат, а не потомок, compilerOptions.
Ответ 2
В версии 0.5 вы можете скрыть файлы и папки
Открыть файлы- > Настройки- > Настройки пользователя и добавить что-то вроде
{
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"jspm_packages" : true,
"node_modules" : true
}
}
Ответ 3
Если вы не предоставите список files
, VSCode скомпилирует все.
{
"compilerOptions": {
"target": "ES5"
}
}
Вы можете изменить это, указав список файлов, которые вы хотите скомпилировать, например:
{
"compilerOptions": {
"target": "ES6"
},
"files": [
"app.ts",
"other.ts",
"more.ts"
]
}
Ответ 4
Вот вам путь, не используйте 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"
}