Dži*_*lić 7 debugging visual-studio-code angular-cli angular
嗨我已经使用angular-cli构建了一个应用程序,我正在尝试使用vs代码和调试器进行chrome扩展调试.过了一会儿,我才能让它发挥作用.会发生什么是我可以在我的打字稿类中设置一个断点但是它被放置在错误的行号上,就像源映射不正确一样.
调试过程 - 打开终端服务而不是转到调试选项卡,然后在vscode中单击F5
我有以下内容:我使用LaunchChrome配置
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "LaunchChrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200",
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"diagnosticLogging": true,
"userDataDir": "${workspaceRoot}/.vscode/chrome",
"sourceMapPathOverrides": {
"webpack:///C:*": "c:/*"
}
},
{
"name": "AttachChrome",
"type": "chrome",
"request": "attach",
"port": 9222,
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"diagnosticLogging": true,
"sourceMapPathOverrides": {
"webpack:///*": "/*"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
角cli.json
{
"project": {
"version": "1.0.0-beta.18",
"name": "frontend"
},
"apps": [
{
"root": "src",
"outDir": "./dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"mobile": false,
"styles": [
"styles.css",
"../semantic/dist/packaged/semantic.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../semantic/dist/packaged/semantic.js",
"../node_modules/chart.js/dist/Chart.bundle.js"
],
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"addons": [],
"packages": [],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
}
Run Code Online (Sandbox Code Playgroud)
tsconfig.json
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"module": "es6",
"moduleResolution": "node",
"outDir": "../dist",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/@types"
]
}
}
Run Code Online (Sandbox Code Playgroud)
我已经更新到angular-cli-beta19-3和typescript 2.0.6并清除了chrome中的缓存,现在它可以工作了.
更新:现在使用角度2.4.1
有趣的是,它不起作用
"sourceMapPathOverrides": {
"webpack:///*": "${webRoot}/*"
}
Run Code Online (Sandbox Code Playgroud)
这里定义https://github.com/Microsoft/vscode-chrome-debug
但它适用于
"sourceMapPathOverrides": {
"webpack:///C:*": "c:/*"
}
Run Code Online (Sandbox Code Playgroud)
和@carpinchosaurio所说的Linux一样
"webpack:///*": "/*"
Run Code Online (Sandbox Code Playgroud)
更新2/21/2017:
使用新版本的angular和typescript,不再需要源映射路径覆盖.
"@angular/compiler-cli": "2.4.8",
"@angular/cli": "1.0.0-beta.32.3",
"typescript": "2.1.6"
angular version 2.4.8
Run Code Online (Sandbox Code Playgroud)
工作设置:
{
"version": "0.2.0",
"configurations": [
{
"name": "LaunchChrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200",
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"userDataDir": "${workspaceRoot}/.vscode/chrome"
}
]
}
Run Code Online (Sandbox Code Playgroud)