最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to debug a Cordova's hook? - Stack Overflow

programmeradmin2浏览0评论

I was wondering if is it possible to debug a javascript hook in Cordova?

My hook is triggered before prepare. My mand is

cordova prepare ios

I currently use Visual Studio Code and there is a plugin "Cordova tools" to debug an app at runtime. But my need is to debug at build time.

Any remandation?

PS : what I mean with debug is real debug, that is to say with breakpoints and display of variables, etc..

I was wondering if is it possible to debug a javascript hook in Cordova?

My hook is triggered before prepare. My mand is

cordova prepare ios

I currently use Visual Studio Code and there is a plugin "Cordova tools" to debug an app at runtime. But my need is to debug at build time.

Any remandation?

PS : what I mean with debug is real debug, that is to say with breakpoints and display of variables, etc..

Share Improve this question asked Jun 7, 2017 at 16:06 pom421pom421 1,9741 gold badge21 silver badges42 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

Updated answer 25 Nov 2019

Since node-inspector is deprecated, here is how I would now do this:

  • Open chrome://inspect in Chrome browser
  • Run 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 debug
  • In the Chrome tab, press inspect on the target to open Chrome Dev Tools
  • Under Filesystem tab, select Add folder to workspace and select the directory inside my Cordova project containing the hook scripts
  • Add a breakpoint to my hook script
  • Press Play in Chrome Dev Tools to proceed and hit my breakpoint

Original answer 7 Jun 2017 Here's how I debug my hook scripts:

  • Install node inspector: npm install -g node-inspector
  • From the Cordova project root directory, run the Cordova mand via node inspector with appropriate options to trigger my hook script, for example:

    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

  • Add a breakpoint
  • Press Resume to continue execution to your breakpoint
  • Then you can interactively debug your hook script:

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:

{
  "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.

发布评论

评论列表(0)

  1. 暂无评论