Chrome Dev Tools调试Ionic Capacitor Angular应用程序使用源映射

huangapple go评论48阅读模式
英文:

Chrome Dev Tools Debugging Ionic Capacitor Angular app with Source Maps

问题

  1. 我在VSCode中使用Ionic 6、Capacitor 4、Angular 14,在Nx Workspace中构建我的应用程序(顺便提一下,我使用VSCode)。
  2. 我通过Nx在项目命令行中运行 nx build my-app --configuration development
  3. 我运行 npx cap copy && npx cap sync 来同步项目。
  4. 我运行 npx cap open android 打开Android Studio项目。
  5. 我选择菜单 Build => Make Project 在Android Studio中。
  6. 我选择菜单 Build => Run(目标是连接的USB手机)。
  7. 我打开Chrome浏览器,导航到 chrome://inspect,然后检查我的移动应用程序以打开Chrome开发工具。
  8. 我使用Ctrl+Shift+F在我的源代码中查找要设置断点的内容,但它跳转到Babel编译的js文件而不是ts文件。
  9. 我得出结论,某种原因导致源映射未正常工作。

这种方式进行调试并不是完全不可能的,但并不如我知道的那样令人愉快。有人能帮我找出问题出在哪里以及如何修复吗?

英文:

I'm using Ionic 6, Capacitor 4, Angular 14, in an Nx Workspace (using VSCode fwiw).

  1. I build my app in VSCode via Nx nx build my-app --configuration development.
  2. I run npx cap copy && npx cap sync on the project command line.
  3. I run npx cap open android to open the Android Studio project.
  4. I choose the menu Build => Make Project in Android Studio.
  5. I choose the menu Build => Run (with my USB-connected phone as the target).
  6. I open Chrome browser, navigate to chrome://inspect, then Inspect my mobile app to open Chrome Dev Tools.
  7. I ctrl+shift+f to find something in my source code to set a breakpoint on, and it goes to a Babel-compiled js file instead of a ts file.
  8. I conclude that somehow source maps aren't working for some reason.

It's not impossible to debug in this way, but it is much less enjoyable than I know it could be. Can anyone help me figure out where things are going wrong and how to fix it?

答案1

得分: 2

使用npx cap sync命令时添加 --inline 选项。

npx cap sync --inline

请注意,不需要运行npx cap copy,因为sync命令包括了复制和更新的功能。如果没有安装新插件,不需要每次都运行sync,只需运行copycopy也有 --inline 选项。

npx cap copy --inline
英文:

Use --inline option on npx cap sync command

npx cap sync --inline

Note, you don’t need to run npx cap copy since sync does copy + update.
If you didn’t install any new plugins you don’t need to run sync every time, just copy, copy also has --inline option

npx cap copy --inline

huangapple
  • 本文由 发表于 2023年3月3日 22:34:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75628384.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定