Jason Crosby
Jason Crosby

Reputation: 3583

Why does my Cordova hook have to be run twice before it works?

I have a Cordova project I am working on that uses broswerify so I can use require() in the mobile app. Everything works good so I am attempting to move the browserifying of my js files to a Cordova hook so I don't have to remember to run browserify before installing the app.

Now when I move the command to browserify my js files to a Cordova hook (before_run), it has to be run twice before I see the changes I made.

  1. Make changes to files.
  2. Run cordova run.... Hook runs successfully and app installs.
  3. In my code editor I see the bundle.js file has the updated code so I know the hook is successfully running the browserify command.
  4. Using Chrome debug tools I can see an Android device still has the old bundle.js code.
  5. I run cordova run... again and now I see the new code in the bundle.js in the Android device.

I'm thinking it may be a timing issue, if that is the case how do I make the Cordova hook wait until the bundle.js file is ready before continuing? If its something else can someone point me in the right direction to get this to work properly? I have tried this about 5 times and every time it does not work the first time but does work the 2nd time.

Upvotes: 0

Views: 200

Answers (1)

csantanapr
csantanapr

Reputation: 5022

Make the hook script run sync for example using an npm script then have a bat or bash script that runs npm

npm run build

Upvotes: 0

Related Questions