在Visual Studio Code中隱藏.js.map文件

本文翻譯自:Hide .js.map files in Visual Studio Code

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 .ts files in the file explorer? 是否可以在文件資源管理器中僅顯示.ts文件?


#1樓

參考:https://stackoom.com/question/28XT3/在Visual-Studio-Code中隱藏-js-map文件


#2樓

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 .js and .js.map files 因此,您可以添加以下內容以隱藏.js.js.map文件

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

As this other answer explains , most people probably only want to hide .js files when there is a matching .ts file. 正如另一個答案所解釋的那樣 ,大多數人可能只想在存在匹配的.ts文件時隱藏.js文件。

So instead of doing: 因此,與其做:

"**/*.js": true

you might want to do: 您可能想做:

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

#3樓

I found this, If you have standard JS files then these will be hidden too which may not always be what you want. 我發現,如果您有標準的JS文件,那麼這些文件也將被隱藏,而這些文件可能並不總是您想要的。 Perhaps this is better as it only hides JS files that match TS files... 也許更好,因爲它只隱藏與TS文件匹配的JS文件...

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

#4樓

I really don't know how this is implemented but for hiding .js files works: 我真的不知道這是如何實現的,但是隱藏.js文件的工作原理是:

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

For hiding .js.map files works: 用於隱藏.js.map文件的方法如下:

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

#5樓

Maybe it's better to hide .map and .js files when they match their corresponding .ts file. .map.js文件與相應的.ts文件匹配時,最好隱藏它們。
You can do that by copying the following lines in VS User Settings (Preferences > User Settings): 您可以通過在“ VS用戶設置”(“首選項”>“用戶設置”)中複製以下行來做到這一點:

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

#6樓

When you are working with TypeScript, you often don't want to see generated JavaScript files in the explorer or in search results. 使用TypeScript時,通常不希望在資源管理器或搜索結果中看到生成的JavaScript文件。 VS Code offers filtering capabilities with a files.exclude setting ( File > Preferences > Workspace Settings) and you can easily create an expression to hide those derived files: VS Code提供了具有files.exclude設置( 文件>首選項>工作區設置)的過濾功能,您可以輕鬆創建一個表達式來隱藏這些派生文件:

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

Similarly hide generated .map files by: 同樣,通過以下方式隱藏生成的.map文件:

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

So you will have a configuration like in: 因此,您將具有如下配置:

settings.json settings.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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章