如何排除文件夹"探索"选项卡?

我试图排除Visual Studio代码中的Explore选项卡上的几个文件夹。为此,我在项目的根目录中添加了下面的jsconfig.json:

{
"compilerOptions": {
"target": "ES6"
},
"exclude": [
"node_modules"
]
}

但是node_modules文件夹在目录树中仍然可见。

我做错了什么?还有其他选择吗?

232818 次浏览

使用files.exclude:

  • 转到文件→偏好→设置(或在Mac上代码→偏好→设置)
  • 选择workspace settings选项卡
  • 将以下代码添加到显示在右侧的settings.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
}
}
}

如果选择文件→偏好→用户设置,则为当前用户全局配置排除文件夹。

在较新的VS Code版本中,你导航到设置(Ctrl+),并确保在右上方选择工作空间设置

enter image description here

然后添加files.exclude选项来指定要排除的模式。

如果你只想从搜索结果中排除一个文件,而不是从文件夹资源管理器中排除,你也可以添加search.exclude

我设法通过禁用验证来删除错误:

{
"javascript.validate.enable": false,
"html.validate.styles": false,
"html.validate.scripts": false,
"css.validate": false,
"scss.validate": false
}

Obs:我的项目是一个PWA使用StyledComponents, React, Flow, Eslint和更漂亮。

在VSCode的新版本中,这移动到一个特定于文件夹的配置块。

  • 转到File ->PreferencesSettings(或Mac上Code ->PreferencesSettings)
  • 选择文件夹设置选项卡

然后添加一个“files.exclude”;块,列出你想要排除的目录glob:

{
"files.exclude": {
"**/bin": true,
"**/obj": true
},
}

enter image description here

在Visual Studio Code 1.28版中,"files.exclude"必须放置在settings节点中。

生成的工作空间文件如下所示:

{
"settings": {
"files.exclude": {
"**/node_modules": true
}
}
}

GUI方式

  1. 进入"File ->偏好→Settings"(或按Ctrl + )然后: 李exclude tutorial via截图 < / >
  2. 类型“exclude"转到搜索栏。
  3. 选择“工作空间”;如果您希望此更改仅影响当前项目,而不是每个项目,请单击TAB。
  4. 点击“添加模式”;按钮。

代码的方式

  1. 打开settings.json文件:

    • 在Mac上按Ctrl + 转变 + PCmd + 转变 + P,然后输入“打开工作空间设置(JSON)”。
    • 或者,在旧版本中,您可以单击GUI选项卡右上角的小{}图标: 李点击方括号图标打开设置。json < / >
  2. 将排除的文件夹添加到files.exclude。还可以查看search.excludefiles.watcherExclude,因为它们可能也有用。这段代码包含了它们的解释和默认值:

     {
    // 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
    }
    }
    

有关其他设置的更多详细信息,请参见官方settings.json引用. c。

有一个< em > Explorer排除< / em >扩展就是做这个的。https://marketplace.visualstudio.com/items?itemName=RedVanWorkshop.explorer-exclude-vscode-extension

它添加了一个选项来隐藏当前文件夹/文件到右键菜单。 它还添加了一个垂直选项卡< em > < / em >隐藏物品到资源管理器菜单,在那里你可以看到当前隐藏的文件&


enter image description here

您可以配置模式来隐藏资源管理器和搜索中的文件和文件夹。

  1. 打开VS用户设置(主菜单:文件>偏好比;设置)。这将打开设置界面。

  2. 在顶部搜索files:exclude

  3. 根据需要使用新的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
}
}

以下是2021年在Mac上使用Visual Studio Code的答案。我使用的是Code v1.60。

  1. 打开设置(command-P)。

  2. 选择工作区选项卡。

enter image description here

  1. 使用“设置”搜索栏搜索“排除”。然后寻找“文件:排除”的部分。点击“添加图案”的蓝色按钮。

enter image description here

  1. 将出现一个新的文本字段。添加要排除的目录的名称。如果目录名为excluded_directory,则输入**/excluded_directory。单击OK。

enter image description here

如果这些文件定义在.gitignore,你可以通过以下方法排除它们:

  • 文件首选项设置(或Mac Code ->偏好→设置)
  • 特性搜索→检查使用忽略文件