使用Visual Studio Code调试Webpack捆绑的节点ts

编程入门 行业动态 更新时间:2024-10-27 10:32:56
本文介绍了使用Visual Studio Code调试Webpack捆绑的节点ts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

(在某种程度上与相关 但更特定于VsCode )

我正在尝试使用Visual Studio代码调试 AngularU入门工具包. 但这会将ts输出合并到单个bundle.js和侧面bundle.js.map :

I m trying to debug the AngularU starter kit with visual studio code. But it's merging the ts output inside a single bundle.js with a side bundle.js.map:

↳web ↳dist ↳client ↳server ⇒bundle.js ⇒bundle.js.map ↳src ⇒server.ts ⇒client.ts

当我尝试运行它时,我从VS UI中得到一个错误:

When i try to run it i m getting an error from VS UI:

request 'launch': cannot launch program '/home/.../web/src/server.ts'; setting the 'outDir' attribute might help

当未合并输出文件时,

outDir 在我的其他项目(不使用webpack)上可以正常工作,但是在这里没有帮助.可以肯定他正在寻找server.js(但是只有bundle.js及其映射文件).

outDir works fine on my others projects (not using webpack) when output files are not merged, but here it doesnt help. Pretty sure he is looking for server.js (but there is only a bundle.js and its map file).

生成的单个文件输出是否有outFile选项?

Is there any outFile option for generated single file ouput?

我的launch.json:

My launch.json:

{ "name": "WebServer", "type": "node", "request": "launch", "program": "./web/src/server.ts", "stopOnEntry": false, "args": [], "cwd": "./web", "runtimeExecutable": null, "runtimeArgs": [ "--nolazy" ], "env": { "NODE_ENV": "development" }, "externalConsole": false, "sourceMaps": true, "outDir": "./web/dist/server" }

编辑:当我将Webpack服务器输出重命名为 server.js 和 server.map.js (而不是捆绑包)时,它会运行.*),但不幸的是,断点无法正常工作:

It does run when i rename the webpack server output as server.js and server.map.js (instead of bundle.*), but the breakpoints are not working unfortunately:

这是server.js.map文件的内容.

根据本教程,将TS编译器和Webpack都配置为创建源地图.

Both TS compiler and Webpack are configured to create sourcemap according to this tutorial.

我想念什么吗?

EDIT2 :断点的问题似乎是映射文件中的源URI.

EDIT2: The probleme with breakpoints seems to be the sources URI in the map file.

当我转动这个

"webpack:///./src/server.ts",

进入此

"../../src/server.ts",

断点正在工作.

推荐答案

这是我的工作方式:

  • 在最低1.1.0版本中具有VsCode(旧版本将与sourceRoot斗争)

  • Have VsCode atLeast 1.1.0 (older will struggle with sourceRoot)

    将捆绑文件设置为与webpack.config.js中的父目录相同的名称

    Set the bundle file the same name as its parent directory in webpack.config.js

    output: { path: path.join(__dirname, 'dist', 'server'), filename: 'server.js' },

  • ,然后在launch.json中将父目录设置为"outdir":

  • and set the parent dir as 'outdir' in launch.json:

    ... "sourceMaps": true, "outDir": "${workspaceRoot}/dist/server", "smartStep":true

  • 要求webpack在webpack.config.json中输出sourcemap的绝对路径

  • Ask webpack to output absolute path for sourcemap in webpack.config.json

    output : { ... devtoolModuleFilenameTemplate : '[absolute-resource-path]', devtoolFallbackModuleFilenameTemplate: '[absolute-resource-path]?[hash]' }

  • 更多推荐

    使用Visual Studio Code调试Webpack捆绑的节点ts

    本文发布于:2023-11-17 06:37:41,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1609177.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:节点   Studio   Visual   Code   ts

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!