如何从Visual Studio代码“浏览”选项卡中排除目录?

问题描述 投票:180回答:6

我正在尝试在Visual Studio代码中的“浏览”选项卡上排除多个文件夹。为此,我在项目的根目录中添加了以下jsconfig.json:

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

但是“node_modules”文件夹仍然在目录树中可见。我究竟做错了什么?还有其他选择吗?

visual-studio-code
6个回答
355
投票

使用files.exclude

  • 转到文件 - >首选项 - >设置(或在Mac代码 - >首选项 - >设置)
  • 选择workspace settings标签
  • 将此代码添加到右侧显示的settings.json文件中: // Place your settings in this file to overwrite default and user 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 } }

如果选择“文件” - >“首选项” - >“用户设置”,则可以为当前用户全局配置排除的文件夹。


68
投票

在较新版本的VS Code中,您可以导航到设置(Ctrl +,),并确保选择右上角的“工作区设置”。

enter image description here

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

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


8
投票

tl;博士

  1. 按Ctrl + Shift + P.
  2. 输入“工作区设置”。
  3. 通过GUI或settings.json更改排除设置:

GUI方式

  1. 在搜索栏中输入“exclude”。
  2. 单击“添加模式”按钮。 Add exclude pattern in VS Code settings

代码方式

  1. 点击右上角的小qazxsw poi图标打开qazxsw poi:qazxsw poi
  2. 将排除的文件夹添加到{}。另请查看settings.jsonClick brackets icon to open settings.json,因为它们也可能有用。此代码段包含其解释和默认值: files.exclude

有关其他设置的更多详细信息,请参阅search.exclude


6
投票

在Visual Studio Code 1.28版中,files.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 } } 节点内。

导致工作区文件看起来像:

official settings.json reference

1
投票

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

  • 转到文件 - >首选项 - >设置(或在Mac代码 - >首选项 - >设置)
  • 选择文件夹设置选项卡

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

"files.exclude"

settings


-8
投票

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

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

Obs:我的项目是使用StyledComponents,React,Flow,Eslint和Prettier的PWA。

© www.soinside.com 2019 - 2024. All rights reserved.