[英]Typescript sourcemap not working in vscode
I have a project which is divided in two part.我有一个项目分为两部分。
1.Typescript project with is compiled to a single javascript file. 1.Typescript 项目被编译为单个 javascript 文件。
2.ASP.NET Core website which use the typescript project for user testing. 2.ASP.NET Core 网站,使用 typescript 项目进行用户测试。
I am generating sourcemaps with typescript, here is my tsconfig.我正在用打字稿生成源映射,这是我的 tsconfig。
{
"extends": "./../tsconfig.json",
"compilerOptions": {
"outFile": "build/app.js",
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": true,
"sourceMap": true,
"target": "es5",
"module": "amd"
},
"include": [
"app/**/*.ts"
],
"exclude": [
"node_modules"
]
}
And file are served this way文件以这种方式提供
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Directory.GetCurrentDirectory() + "/../typescriptapp/build"),
RequestPath = new PathString("/typescriptapp")
});
When debugging in chrome, it work, I can see all typescripts files.在 chrome 中调试时,它工作正常,我可以看到所有的打字稿文件。 However, when i try to debug in vscode or visualstudio2017, breakpoint are not enabled properly.
但是,当我尝试在 vscode 或 visualstudio2017 中调试时,断点未正确启用。 I would prefer not to copy the whole typescript app into the webapp to avoid editing the wrong file.
我不想将整个打字稿应用程序复制到 webapp 中以避免编辑错误的文件。
I tried changing the "outDir" in the tsconfig, but went i do so Chrome debugging doesn't work because it look for the full path in localhost:43345\\typescriptapp\\C:\\typescriptapp\\app\\app.ts我尝试更改 tsconfig 中的“outDir”,但是我这样做 Chrome 调试不起作用,因为它在 localhost:43345\\typescriptapp\\C:\\typescriptapp\\app\\app.ts 中查找完整路径
What am I missing to enable debugging in both vscode and visualstudio2017 while keeping it working in chrome?在 vscode 和 visualstudio2017 中启用调试同时保持它在 chrome 中工作,我缺少什么?
Update 21/03/2018 - Added launch.json 21/03/2018 更新 - 添加了launch.json
{
"type": "chrome",
"request": "launch",
"name": "typescriptapp - chrome",
"url": "http://localhost:5000",
"webRoot": "${workspaceFolder}/webapp/wwwroot",
"sourceMaps": true,
"trace": true
},
{
"name": "webapp",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "",
"program": "${workspaceRoot}/webapp/bin/Debug/netcoreapp2.0/webapp.dll",
"args": [],
"cwd": "${workspaceRoot}/webapp",
"stopAtEntry": false,
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceRoot}/webapp/Views"
}
}
Thanks谢谢
Thanks @Aviad Hadad pointed me on the right track.谢谢@Aviad Hadad 为我指明了正确的轨道。
I tried changing the vscode launch settings to "webRoot": "${workspaceFolder}\\..\\typescriptapp\\build"
and it was possible to debug my typescript project.我尝试将 vscode 启动设置更改为
"webRoot": "${workspaceFolder}\\..\\typescriptapp\\build"
并且可以调试我的打字稿项目。 However I could not debug wepapp file this way.但是我无法以这种方式调试 wepapp 文件。
My solution was to keep this "webRoot":"${workspaceFolder}/webapp/wwwroot"
but I added a step in my build process which compile my project a second time in my webapp.我的解决方案是保留这个
"webRoot":"${workspaceFolder}/webapp/wwwroot"
但我在我的构建过程中添加了一个步骤,它在我的 webapp 中第二次编译我的项目。
tsc -p '.\typescriptapp\tsconfig.json' --outFile .\webapp\wwwroot\js\typescriptapp\typescriptapp.js;
This way, sourcemaps are mapped properly for vscode.通过这种方式,可以为 vscode 正确映射源映射。 I had to change a bit static files served so it can work with chrome.
我不得不更改一些提供的静态文件,以便它可以与 chrome 一起使用。
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Directory.GetCurrentDirectory() + "/../typescriptapp"),
RequestPath = new PathString("/typescriptapp")
});
I faced same issue.我遇到了同样的问题。 however it resolved when used inline source maps.
但是当使用内联源映射时它解决了。 Maybe it can work with you as well.
也许它也可以和你一起工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.