How to view an HTML file in the browser with Visual Studio Code

前端 未结 23 1694
[愿得一人]
[愿得一人] 2020-11-28 17:43

How can I view my HTML code in a browser with the new Microsoft Visual Studio Code?

With Notepad++ you have the option to Run in a browser. How can I do the same thi

23条回答
  •  情话喂你
    2020-11-28 17:50

    Open custom Chrome with URL from prompt

    {
      "version": "2.0.0",
      "tasks": [
        {
          "label": "Open Chrome",
          "type": "process",
          "windows": {
            "command": "${config:chrome.executable}"
          },
          "args": ["--user-data-dir=${config:chrome.profileDir}", "${input:url}"],
          "problemMatcher": []
        }
      ],
      "inputs": [
        {
          "id": "url",
          "description": "Which URL?",
          "default": "http://localhost:8080",
          "type": "promptString"
        }
      ]
    }
    

    Open custom Chrome with active file

    {
      "label": "Open active file in Chrome",
      "type": "process",
      "command": "chrome.exe",
      "windows": {
        "command": "${config:chrome.executable}"
      },
      "args": ["--user-data-dir=${config:chrome.profileDir}", "${file}"],
      "problemMatcher": []
    },
    

    Notes

    • if necessary, replace windows property by other OS
    • replace ${config:chrome.executable} with your custom chrome location, e.g. "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
    • replace ${config:chrome.profileDir} with your custome chrome profile directory, e.g. "C:/My/Data/chrome/profile" or leave it out
    • You can keep the variables like above if you want. To do so, add following entries in settings.json - user or workspace - , adjust paths to your needs:
    "chrome.executable": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
    "chrome.profileDir": "C:/My/Data/chrome/profile"
    
    • You could re-use these variables e.g. in launch.json for debugging purposes: "runtimeExecutable": "${config:chrome.executable}"

提交回复
热议问题