我正在尝试排除Visual Studio代码中的Explore选项卡上的几个文件夹。为此,我添加了以下jsconfig。Json到我的项目的根:
{
"compilerOptions": {
"target": "ES6"
},
"exclude": [
"node_modules"
]
}
但是node_modules文件夹在目录树中仍然可见。
我做错了什么?还有其他选择吗?
我正在尝试排除Visual Studio代码中的Explore选项卡上的几个文件夹。为此,我添加了以下jsconfig。Json到我的项目的根:
{
"compilerOptions": {
"target": "ES6"
},
"exclude": [
"node_modules"
]
}
但是node_modules文件夹在目录树中仍然可见。
我做错了什么?还有其他选择吗?
当前回答
使用files.exclude:
转到文件->首选项->设置(或在Mac代码->首选项->设置) 选择工作区设置选项卡 将此代码添加到设置中。右侧显示Json文件:
// Place your settings in this file to overwrite default and user settings.
{
"settings": {
"files.exclude": {
"**/.git": true, // this is a default value
"**/.DS_Store": true, // this is a default value
"**/node_modules": true, // this excludes all folders
// named "node_modules" from
// the explore tree
// alternative version
"node_modules": true // this excludes the folder
// only from the root of
// your workspace
}
}
}
如果您选择了文件->首选项->用户设置,那么您将为当前用户全局配置排除文件夹。
其他回答
如果这些文件定义在.gitignore,你可以通过以下方法排除它们:
文件->首选项->设置(或Mac代码->首选项->设置) 功能->搜索->检查使用忽略文件
在新版本的VS Code中,你导航到设置(Ctrl+,),并确保选择右上角的工作区设置。
然后添加一个文件。选项,指定要排除的模式。
您还可以添加搜索。如果您只想从搜索结果中排除某个文件,而不是从文件夹资源管理器中排除,则选择“排除”。
有一个资源管理器排除扩展就是这样做的。https://marketplace.visualstudio.com/items?itemName=RedVanWorkshop.explorer-exclude-vscode-extension
它添加了一个选项来隐藏当前文件夹/文件到右键菜单。 它还添加了一个垂直选项卡隐藏项目到资源管理器菜单,在那里您可以看到当前隐藏的文件和文件夹,并可以轻松切换它们。
您可以配置模式来隐藏资源管理器和搜索中的文件和文件夹。
打开VS用户设置(主菜单:File > Preferences > Settings)。这将打开设置界面。 搜索文件:排除在搜索的顶部。 根据需要使用新的glob模式配置用户设置。在本例中,添加这个模式node_modules/,然后单击OK。模式语法非常强大。您可以在跨文件搜索主题下找到模式匹配的详细信息。
{
"files.exclude": {
".vscode":true,
"node_modules/":true,
"dist/":true,
"e2e/":true,
"*.json": true,
"**/*.md": true,
".gitignore": true,
"**/.gitkeep":true,
".editorconfig": true,
"**/polyfills.ts": true,
"**/main.ts": true,
"**/tsconfig.app.json": true,
"**/tsconfig.spec.json": true,
"**/tslint.json": true,
"**/karma.conf.js": true,
"**/favicon.ico": true,
"**/browserslist": true,
"**/test.ts": true,
"**/*.pyc": true,
"**/__pycache__/": true
}
}
桂路
进入“文件->首选项->设置”(或按Ctrl +,),然后: 在搜索栏中输入“exclude”。 如果您希望此更改只影响当前项目而不是每个项目,则选择“Workspace”选项卡。 点击“添加图案”按钮。
代码的方式
To open the settings.json file: Press Ctrl + Shift + P or Cmd + Shift + P on Mac, then type "Open Workspace Settings (JSON)". OR, on older versions you can click the little {} icon at the top right corner of the GUI tab: Add excluded folders to files.exclude. Also check out search.exclude and files.watcherExclude as they might be useful too. This snippet contains their explanations and defaults: { // Configure glob patterns for excluding files and folders. // For example, the files explorer decides which files and folders to show // or hide based on this setting. // Read more about glob patterns [here](https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options). "files.exclude": { "**/.git": true, "**/.svn": true, "**/.hg": true, "**/CVS": true, "**/.DS_Store": true }, // Configure glob patterns for excluding files and folders in searches. // Inherits all glob patterns from the `files.exclude` setting. // Read more about glob patterns [here](https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options). "search.exclude": { "**/node_modules": true, "**/bower_components": true }, // Configure glob patterns of file paths to exclude from file watching. // Patterns must match on absolute paths // (i.e. prefix with ** or the full path to match properly). // Changing this setting requires a restart. // When you experience Code consuming lots of cpu time on startup, // you can exclude large folders to reduce the initial load. "files.watcherExclude": { "**/.git/objects/**": true, "**/.git/subtree-cache/**": true, "**/node_modules/*/**": true } }
其他配置请参见官方配置。json参考。