typescript 在 Visual Studio Code 中隐藏 .js.map 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31587949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:43:38  来源:igfitidea点击:

Hide .js.map files in Visual Studio Code

typescriptvisual-studio-codevscode-settings

提问by Tyler

I am working on a typescript project in Visual Studio code and would like to hide the .js.map(and maybe even the .js) files from appearing in the file explorer.

我正在 Visual Studio 代码中处理打字稿项目,并希望隐藏.js.map(甚至可能是.js)文件,以免出现在文件资源管理器中。

Is it possible to display only the .tsfiles in the file explorer?

是否可以仅显示.ts文件资源管理器中的文件?

回答by Brocco

In your settings (either user or workspace) there is a setting that you can tweak to hide anything you'd like:

在您的设置(用户或工作区)中有一个设置,您可以调整以隐藏您想要的任何内容:

{
    "files.exclude": {
        "**/.git": true,
        "**/.DS_Store": true
    }
}

So you can add in the following to hide .jsand .js.mapfiles

所以你可以添加以下内容来隐藏.js.js.map文件

"**/*.js": true,
"**/*.js.map": true

As this other answer explains, most people probably only want to hide .jsfiles when there is a matching .tsfile.

正如另一个答案所解释的那样,大多数人可能只想.js在有匹配.ts文件时隐藏文件。

So instead of doing:

所以,而不是做:

"**/*.js": true

you might want to do:

你可能想要这样做:

"**/*.js": {"when": "$(basename).ts"}

回答by AlwaysLearning

I found this, If you have standard JS files then these will be hidden too which may not always be what you want. Perhaps this is better as it only hides JS files that match TS files...

我发现了这一点,如果你有标准的 JS 文件,那么这些文件也会被隐藏,这可能并不总是你想要的。也许这更好,因为它只隐藏与 TS 文件匹配的 JS 文件......

{
    "files.exclude": {
        "**/.git": true,
        "**/.DS_Store": true,
        "**/*.js.map": true,
        "**/*.js": {"when": "$(basename).ts"}
    }
}

回答by Luka

I really don't know how this is implemented but for hiding .jsfiles works:

我真的不知道这是如何实现的,但隐藏.js文件的工作原理是:

"**/*.js": {"when": "$(basename).ts"}

For hiding .js.mapfiles works:

对于隐藏.js.map文件作品:

"**/*.js.map": {"when": "$(basename)"}

回答by Asim K T

When you are working with TypeScript, you often don't want to see generated JavaScript files in the explorer or in search results. VS Code offers filtering capabilities with a files.excludesetting (File > Preferences > WorkspaceSettings) and you can easily create an expression to hide those derived files:

当您使用 TypeScript 时,您通常不希望在资源管理器或搜索结果中看到生成的 JavaScript 文件。VS Code 通过files.exclude设置(文件 > 首选项 > 工作区设置)提供过滤功能,您可以轻松创建表达式来隐藏这些派生文件:

"**/*.js": { "when": "$(basename).ts"}

Similarly hide generated .mapfiles by:

同样隐藏生成的.map文件:

 "**/*.js.map": { "when": "$(basename)"}

So you will have a configuration like in:

因此,您将拥有如下配置:

settings.json

设置.json

// Place your settings in this file to overwrite default and user settings.
{
    "files.exclude": {
        "**/*.js": { "when": "$(basename).ts"},
        "**/*.js.map": { "when": "$(basename)"}
    }
}

Link: https://code.visualstudio.com/docs/languages/typescript#_hiding-derived-javascript-files

链接:https: //code.visualstudio.com/docs/languages/typescript#_hiding-derived-javascript-files

回答by YourAboutMeIsBlank

John Papa Twitter LINKsays use the following:

John Papa Twitter LINK说使用以下内容:

"files.exclude": {
        "**/.git": true,
        "**/.DS_Store": true,
        "**/*.js" : {
            "when": "$(basename).ts"
        },
        "**/*.js.map": {
            "when": "$(basename)"
        }
}

回答by duodvk

From the official doc:

来自官方文档

to exclude JavaScript files generated from both .ts and .tsx source files, use this expression:

要排除从 .ts 和 .tsx 源文件生成的 JavaScript 文件,请使用以下表达式:

"**/*.js": { "when": "$(basename).ts" },
"**/**.js": { "when": "$(basename).tsx" }

This is a bit of a trick. The search glob pattern is used as a key. The settings above use two different glob patterns to provide two unique keys but the search will still match the same files.

这是一个小技巧。搜索全局模式用作键。上面的设置使用两个不同的 glob 模式来提供两个唯一的键,但搜索仍将匹配相同的文件。

UPDATE 10/3/2017:with this trick we have a problem with "search in folder". Please see the issue

2017 年 10 月 3 日更新:使用此技巧,我们遇到了“在文件夹中搜索”的问题。请看问题

回答by Daniel Eduardo Delgado Diaz

1. Go to preferences > settings

1. 转到首选项 > 设置

enter image description here

enter image description here

2. Click on "Edit on settings.json" (It's on the bottom of the image)

2. 点击“Edit on settings.json”(在图片底部)

enter image description here

enter image description here

3. Update the object json as you can see in the image. Then save your changes Ctrl + Sand that's all.

3. 如您在图像中所见,更新对象 json。然后保存您的更改Ctrl + S,仅此而已。

"files.exclude": {
    "**/*.js": {"when": "$(basename).ts"}
}

enter image description here

enter image description here

回答by Aravind

Add these settings to your settings.jsonin your .vscodefolder

添加这些设置到您settings.json.vscode文件夹

// Place your settings in this file to overwrite default and user settings.
{
    "files.exclude" :{
    "**/.git":true,
    "**/.DS_Store":true,
    "**/*.map":true,
    "**/app/**/*.js":true

    }
}

If the settings.json is not available click on File --->Preferences -->Workspace Settings.

如果 settings.json 不可用,请单击文件--->首选项-->工作区设置。

回答by mutlugokhan

Please add the following lines in "User Settings" panel in order to override "Default Settings". You can hide files {basename}.js and {basename}.js.map when you create file as {basename}.ts.

请在“用户设置”面板中添加以下行以覆盖“默认设置”。当您将文件创建为 {basename}.ts 时,您可以隐藏文件 {basename}.js 和 {basename}.js.map。

"files.exclude": {
        "**/*.js": {
            "when": "$(basename).ts"
        },
        "**/*.js.map": {
            "when": "$(basename)"
        }        
    }

回答by mvecchione

Maybe it's better to hide .mapand .jsfiles when they match their corresponding .tsfile.
You can do that by copying the following lines in VS User Settings (Preferences > User Settings):

也许当它们匹配相应的文件时隐藏.map.js文件会更好.ts
您可以通过在 VS 用户设置(首选项 > 用户设置)中复制以下几行来做到这一点:

// Workspace settings
"files.exclude": {
        "**/*.js":  {"when": "$(basename).ts"},
        "**/*.map": true
 }