提问者:小点点

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


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

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

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


共3个答案

匿名用户

使用文件。排除:

> ;首选项-&>;设置(或Mac代码-&>首选项-&>设置)/LI>

  • 选择选项卡/li> 文件:

    // 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代码中,您将导航到settings(KBDCTRL/KBD+KBD,/KBD),并确保选择右上方的Workspace settings。

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

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

    匿名用户

      ++++ 排除设置

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

    有关其他设置的更多细节,请参见官方的参考。