I'm using Cordova without Ionic or any other Framework. My problem is that I don't find any hot reload features or plugins for Cordova without using Ionic. Is there any solution to live reload on the iOS simulator without any frameworks?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
I've implemented a custom way of 'hot reloading' in Cordova. I don't know how original it is but it works well for my needs. In broad lines it works like this: in development mode a static webserver is started and cordova is instructed that the content is the url of this server:
<content src="http://10.0.3.2:8080" />
.The static server also listens to changes in the assets (js/css/html) and auto reloads. We use gulp connect (https://www.npmjs.com/package/gulp-connect) to achieve this.
In production mode you have to compile the assets and instruct cordova to use the regular static file to load your app.
Details:
In cordova.xml this is the line that tells cordova where to start the app:
So this has to be replaced with a 'dynamic' version that would allow hot reload. I achieved this by using
gulp-connect
which starts a static file server.I created two tasks which switch the cordova configuration in development and in production:
One important thing you have to ensure that the Cordova javascript files are accessible by the development web server. Again, I achieved this with two tasks for development/production.
I am using gulp here but this can be implemented using any task runner, and of course for other platforms you have to modify this code a bit.
Hope this helps.