I was wondering if is it possible to debug a javascript hook in Cordova?
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. 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..
Updated answer 25 Nov 2019
Since node-inspector
is deprecated, here is how I would now do this:
chrome://inspect
in Chrome browsernode --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 debuginspect
on the target to open Chrome Dev ToolsAdd folder to workspace
and select the directory inside my Cordova project containing the hook scriptsOriginal answer 7 Jun 2017 Here's how I debug my hook scripts:
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:
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.