Search code examples
visual-studio-codenode-modules

Visual Studio Code: make exception to files.exclude?


So in Visual Studio Code, I have a .vscode/settings.json which defines some directories to not show.

I have some node_modules that are specific to my project and maintained inside my repo. They all start with mycompany. I'd like to show those in VSCode, but not others.

Here's what I have so far in .vscode/settings.json:

{
    // From http://stackoverflow.com/questions/33258543/how-can-i-exclude-a-directory-from-visual-studio-code-explore-tab
    "files.exclude": {
        "**/.git": true,        
        "**/.DS_Store": true,
        "**/.vscode": true,
        "**/.sass-cache": true,
        "node_modules/mycompany**": false, // Hoping this will override next line
        "node_modules/**": true
    }
}

I've tried swapping the order of the last two lines but that doesn't work either. How can I ignore all files in a directory unless they start with a particular set of characters?


Solution

  • I was trying to do the same thing, and also couldn't find a way to achieve this via files.exclude setting, however I found a workaround utilizes another setting - "explorer.excludeGitIgnore": true.

    Enabled this setting, added .gitignore that expresses what I need, which in your case would be:

    # .gitignore
    node_modules/**
    !node_modules/mycompany**
    

    Note: this works even though I am not using git in this repo, I basically have a .gitignore that is not in any git repo.