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

时间:2015-10-21 11:49:42

标签: visual-studio-code

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

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

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

7 个答案:

答案 0 :(得分:340)

使用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 
        }
    }
    

如果您选择文件 - >偏好 - >用户设置然后为当前用户全局配置排除文件夹。

答案 1 :(得分:66)

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

enter image description here

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

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

答案 2 :(得分:5)

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

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

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

答案 3 :(得分:3)

tl; dr

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

GUI方式

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

代码方式

  1. 单击右上角的小{}图标以打开settings.jsonClick brackets icon to open settings.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
      }
    }
    

有关其他设置的更多详细信息,请参见official settings.json reference

答案 4 :(得分:0)

有一个 Explorer Exclude 扩展确实可以做到这一点。 https://marketplace.visualstudio.com/items?itemName=RedVanWorkshop.explorer-exclude-vscode-extension

它在右键菜单中添加了一个隐藏当前文件夹/文件的选项。 它还在浏览器菜单中添加了一个垂直选项卡 Hidden Items ,您可以在其中查看当前隐藏的文件和文件夹,并可以轻松地对其进行切换。


enter image description here

答案 5 :(得分:0)

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

  1. 打开VS用户设置(主菜单:文件>首选项>设置)。这将打开设置屏幕。

  2. 在顶部的搜索中搜索files:exclude

  3. 根据需要用新的glob模式配置用户设置。在这种情况下,请添加此模式node_modules /,然后单击“确定”。模式语法功能强大。您可以在“搜索整个文件”主题下找到模式匹配的详细信息。

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

答案 6 :(得分:-8)

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

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

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

相关问题