zoukankan      html  css  js  c++  java
  • How to debug an Angular 2 application with Chrome and VS Code

    In this blogpost I want to show you how to debug an Angular 2 application with Chrome and VS Code.

    First of all you need to install the extension in VS Code.

    You can find it here

    https://github.com/Microsoft/vscode-chrome-debug

    or search in the extensions tab for the plugin directly:

    How to debug an Angular 2 application with Chrome and VS CodeAfter installing you probably have to enable the plugin and restart VS Code but in the end you will see your folder structure like normal. Then head over to the debug tab and press the button for creating you an new configuration and select the “Chrome” environment.

    howtodebuganangular2applicationwithchromeandvscode_02After doing this the extension created a new folder (if you do not have it already) called “.vscode” and a “launch.json” in it initially looking like this:

     1 {
     2     "version": "0.2.0",
     3     "configurations": [
     4         {
     5             "name": "Launch Chrome against localhost, with sourcemaps",
     6             "type": "chrome",
     7             "request": "launch",
     8             "url": "http://localhost:8080",
     9             "sourceMaps": true,
    10             "webRoot": "${workspaceRoot}"
    11         },
    12         {
    13             "name": "Attach to Chrome, with sourcemaps",
    14             "type": "chrome",
    15             "request": "attach",
    16             "port": 9222,
    17             "sourceMaps": true,
    18             "webRoot": "${workspaceRoot}"
    19         }
    20     ]
    21 }

    Our folder strucutre tells us that the files are served from the root.

    howtodebuganangular2applicationwithchromeandvscode_03So the “”webRoot”: “${workspaceRoot}”” -setting is good to go for us. We will open a new Chrome instance but it needs an existing running server. So if you use something like “lite-server” you can easily type “lite-server” at the root of your webapplication or place it in your npm command chain in the “npm start” command. This is what I did. But before we go we need to sdjust the urls where the server is running on and the url where the Chrome instance is starting.

    So replace the port in the config file with the port from your lite-server. In my cae thats “3000”. This is how your config look like then:

     1 {
     2     "version": "0.2.0",
     3     "configurations": [
     4         {
     5             "name": "Launch Chrome against localhost, with sourcemaps",
     6             "type": "chrome",
     7             "request": "launch",
     8             "url": "http://localhost:3000",
     9             "sourceMaps": true,
    10             "webRoot": "${workspaceRoot}"
    11         },
    12         {
    13             "name": "Attach to Chrome, with sourcemaps",
    14             "type": "chrome",
    15             "request": "attach",
    16             "port": 9222,
    17             "sourceMaps": true,
    18             "webRoot": "${workspaceRoot}"
    19         }
    20     ]
    21 }

    Then start the lite server and just hit “play”

    howtodebuganangular2applicationwithchromeandvscode_04

    howtodebuganangular2applicationwithchromeandvscode

    Chrome starts and you can debug your page in VS Code. Of course you can also confugre Chrome to attach directly. See here for examples:

    https://github.com/Microsoft/vscode-chrome-debug/wiki/Examples

    Hope this helps anybody

    BR

    Fabian

  • 相关阅读:
    常用坐标系椭球参数整理
    ArcEngine编辑保存错误:Unable to create logfile system tables
    ArcEngine:The XY domain on the spatial reference is not set or invalid错误
    dockManager中DockPanel的刷新问题!
    ibatis实现Iterate的使用
    mongodb用子文档做为查询条件的两种方法
    Eclipse中的文件导航插件StartExplorer
    mongoVUE的增删改查操作使用说明
    什么是脏读,不可重复读,幻读
    转:Maven常用命令
  • 原文地址:https://www.cnblogs.com/cjxhd/p/6129985.html
Copyright © 2011-2022 走看看