I observed the following:
Ever since I started using Ionic Deploy to publish updates via “ionic upload …”, I’m no longer able to work with the iOS simulator in live-reload mode (“ionic emulate ios --livereload”).
Code changes do not get applied, until I run “ionic upload” and then re-run “ionic emulate ios”.
When I run “ionic emulate ios --livereload” and change a file, I only see these lines in the terminal, but nothing changes in the iOS simulator:
I thought that “ionic emulate” works completely independent from “ionic upload”, serving me the current state of my code. But now it looks like the two are somehow tied together: “ionic emulate” serves me the state of the app, which was last deployed via “ionic upload”.
Am I missing something regarding “ionic emulate” and “ionic upload”?
How are you able to emulate with live-reloading AND keep using Ionic Deploy?
Edit: New system information after upgrading to latest versions:
You should upgrade to the current Ionic CLI v3.1.2 (npm install -g ionic).
It doesn’t really makes sense for us to debug an obsolete version of the CLI.
Then you should also upgrade Ionic App Scripts to the current version 1.3.7.
ionic upload takes whatever is in your /www and uploads that to Ionic’s servers, it probably also builds from /src to /www first - I am not sure.
ionic cordova emulate * first kicks off a build (which gets put into www), then cordova emulate which probably cordova prepares the result of that build to the www in the platform folder, and then starts an emulator with the project in the platform folder (containing the www).
Which both doesn’t really explain your problems of course, only shows how this stuff is interconnected by using the same /www folder or a build run by Ionic as a base.
Thanks for the explanation!
Unfortunately the problem persists after uprading @ionic/cli-plugin-cordova and @ionic/cli-plugin-ionic-angular to version 1.1.2.
When I save a changed file (e.g. a page’s HTML template), while “ionic cordova emulate ios --livereload” is running, the build finishes incredibly fast (~200ms), as you can see in the screenshot:
The initial build takes more than 21 seconds on my machine:
I now realize that initially it says “build dev started”, while file changes trigger “build started” without the “dev”.
Perhaps this is relevant?
Another observation I made is the following:
The reason why “emulate” only serves me the up-to-date code after e.g. “ionic upload --note “foo” --deploy production” was entered in terminal, is that the app then updates itself while running in Simulator, because this code in app.component.ts’s constructor gets executed (based on examples from here: https://docs.ionic.io/services/deploy/):
Apparently “emulate” always serves me the latest snapshot that was loaded in the app via Ionic Deploy. (It looks like it has nothing to do with the --livereload option.)
Any thoughts on what I should try next?
Does it make sense to start a new empty project based on the same package.json and see if “emulate” works there as expected?
Or perhaps someone has a better idea to share?
Unfortunately the issue got closed with this response:
The logic of when an app updates is up to you. If you have it check for updates from your deploy channel when your app boots up, it’s going to update the app with the latest snapshot from that channel. That example is to show the simplest example of deploy functionality.
If you want to continue updating when the app boots up, I suggest you look into setting up different environments (dev vs prod) for your app.
Either this response misses the point of my issue, or I’m lacking some basic understanding.
I think it all boils down to this question: Should ionic cordova emulate ios --livereload always build and display the app based on the actual code on my development machine?
Ok, we didn’t talk about your “Ionic Deploy” code here yet.
Does your app update via Ionic Deploy after being started with --livereload? If so, it naturally destroys livereload as the complete app is replaced with the downloaded version of the app. Not ionic upload is the problem, but that your code always updating the app when a new snapshot is available.
Does the same problem happen if you remove the “autoupdate my app” code?
Usually when emulating, I’m in development mode and I don’t apply any uploaded snapshots.
I only use Ionic Deploy, if the app is running in production mode.
So, basically my deploy logic looks like this now: