[英]How to debug a Cordova's hook?
I was wondering if is it possible to debug a javascript hook in Cordova?我想知道是否可以在 Cordova 中调试 javascript 钩子?
My hook is triggered before prepare.我的钩子在准备之前被触发。 My command is
我的命令是
cordova prepare ios
I currently use Visual Studio Code and there is a plugin "Cordova tools" to debug an app at runtime.我目前使用 Visual Studio Code,并且有一个插件“Cordova 工具”可以在运行时调试应用程序。 But my need is to debug at build time.
但我的需要是在构建时进行调试。
Any recommandation?有什么推荐吗?
PS : what I mean with debug is real debug, that is to say with breakpoints and display of variables, etc.. PS:我说的debug是真正的debug,也就是断点和变量显示等。
Updated answer 25 Nov 2019 2019 年 11 月 25 日更新的答案
Since node-inspector
is deprecated, here is how I would now do this:由于不推荐使用
node-inspector
器,因此我现在将如何执行此操作:
chrome://inspect
in Chrome browserchrome://inspect
node --inspect --inspect-brk /path/to/node_modules/cordova/bin/cordova prepare
from the root of my Cordova app project which contains the hook scripts I wish to debugnode --inspect --inspect-brk /path/to/node_modules/cordova/bin/cordova prepare
包含我希望调试的钩子脚本inspect
on the target to open Chrome Dev Toolsinspect
以打开 Chrome 开发工具Add folder to workspace
and select the directory inside my Cordova project containing the hook scriptsAdd folder to workspace
并选择包含钩子脚本的 Cordova 项目中的目录Original answer 7 Jun 2017 Here's how I debug my hook scripts:原始答案 2017 年 6 月 7 日这是我调试钩子脚本的方法:
npm install -g node-inspector
npm install -g node-inspector
From the Cordova project root directory, run the Cordova command via node inspector with appropriate options to trigger my hook script, for example:从 Cordova 项目根目录,通过节点检查器运行 Cordova 命令并使用适当的选项来触发我的钩子脚本,例如:
node-debug /path/to/node_modules/cordova/bin/cordova prepare
When node inspector opens in a Chrome tab, browse Sources to find your hook script当节点检查器在 Chrome 选项卡中打开时,浏览源以查找您的钩子脚本
You can debug a Cordova hook easily inside VS Code without opening a browser by putting this launch configuration to the .vscode/launch.json
file at the root of your project:通过将此启动配置放入项目根目录下的
.vscode/launch.json
文件,您可以在 VS Code 中轻松调试 Cordova 挂钩,而无需打开浏览器:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Cordova Prepare",
"program": "C:/Program Files/nodejs/node_modules/cordova/bin/cordova", // This is for winx64 adjust it to your platform
"args": ["prepare"]
}
]
}
After just put a breakpoint in the hook's file and hit F5 or go to the Debug and Run
side menu and press the Play button at the top next to the "Cordova Prepare" text.在钩子的文件中放置一个断点并按 F5 或转到“
Debug and Run
侧菜单并按“Cordova Prepare”文本旁边顶部的“播放”按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.