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

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

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

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


当前回答

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

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

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

其他回答

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

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

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

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

然后添加一个文件。选项,指定要排除的模式。

您还可以添加搜索。如果您只想从搜索结果中排除某个文件,而不是从文件夹资源管理器中排除,则选择“排除”。

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

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

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

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

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

文件->首选项->设置(或Mac代码->首选项->设置) 功能->搜索->检查使用忽略文件

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

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