I have an ionic 2 project, which builds for iOS, android and browser (it is a PWA as well as a native app).
I need to run a simple script to munge my index.html file when it is not running in cordova, i.e. in the browser i.e. the PWA mode.
I looked into cordova hooks, and have set up the following in my config.xml which works great when I do ionic build browser. Since my CI server builds this way to CI deploy to the website, this works fine.
<hook src="scripts/insert_onesignal_webpush.js" type="after_serve"/>
However, when I do ionic serve during local development, the script does not run and I have to manually run it to get my index.html in the right state for local development. A bit annoying. I looked into the before_serve cordova hook but that does not seem to run during ionic serve.
I also tried creating a .sh script that invokes my script right after calling ionic serve, but it seems that there is no live-reload if index.html is modified… so i still have to refresh the browser after ionic serve to get the updated index.html… better, but not ideal.
I am looking for some way to hook into ionic serve so that I get the right index.html file on the first attempt… without any need to do any manual script invocations or browser refreshes. Perhaps the ionic_copy config for ionic-app-scripts could do it, see https://ionicframework.com/docs/v2/resources/app-scripts/, but I don’t see any examples of calling it to do something like my requirement (since I need the index.html munged only on ionic serve and ionic build browser… not modify the copy step for all builds including iOS and android)… ideas please?