我正在尝试排除Visual Studio代码中的Explore选项卡上的几个文件夹。为此,我添加了以下jsconfig。Json到我的项目的根:

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

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

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


当前回答

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

打开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
      }
    }

其他回答

在Visual Studio Code的1.28版中。“排除”必须放置在设置节点中。

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

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

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

打开设置(command-P)。 选择工作区选项卡。

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

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

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

如果您选择了文件->首选项->用户设置,那么您将为当前用户全局配置排除文件夹。

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

打开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
      }
    }

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

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

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

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