Skip to content

Instantly share code, notes, and snippets.

@revolunet
Last active September 4, 2015 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revolunet/328193b350a056d730a5 to your computer and use it in GitHub Desktop.
Save revolunet/328193b350a056d730a5 to your computer and use it in GitHub Desktop.
Cordova before_prepare hook to point the webview to your WEBVIEW_SRC env variable.
#!/usr/bin/env node
/*
cordova webview src changer : force the webview startPage with the env var `WEBVIEW_SRC`.
put this script in hooks/before_prepare/webview-src.js and chmod +x it
ex: `WEBVIEW_SRC=http://192.168.2.30:9999 cordova prepare`
On port 9999 serve the platforms/ios/www folder (which includes cordova.js)
This way you dont have to recompile your app to test your web-app changes in the final cordova environnement.
You have to run cordova prepare to update the platforms/ios/www folder though
*/
var lib = require('cordova').cordova_lib;
var config = new lib.configparser(__dirname + '/../../config.xml');
function setWebviewSrc(src) {
config.doc.find('content').set('src', src);
}
setWebviewSrc(process.env.WEBVIEW_SRC);
if (process.env.WEBVIEW_SRC) {
console.log('set webview startPage to ' + process.env.WEBVIEW_SRC);
setWebviewSrc(process.env.WEBVIEW_SRC);
} else {
setWebviewSrc('index.html');
}
config.write();
@shprink
Copy link

shprink commented Sep 4, 2015

wordpress-clients/hybrid@36bd651 Beaucoup plus sympa! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment