ionic2 serve + cordova plugins

Hi All,

I’ve used phonegap a couple of years ago and I’ve felt the pain of testing the apps in the browser.
I’ve recently discovered Ionic and now I’m giving it a try, specifically Ionic V2, with the hope that it will be easier.

I’m trying to use the cordova-plugin-file which according to its documentation works also on browsers. How can I use “ionic serve” while using these kind of plugins that supposedly should work in the browsers ?

Thanks

edit:

ionic run browser works… but it doesn’t have the live-reload which is so handy… That’s means that I need to restart it everytime I make a change (+10 seconds). Am I missing anything ?

What issue are you running into? What code are you trying to run and what is happening? Any errors occurring in the console?

As you mentioned, Cordova plugins won’t work through the browser, but if they implement a HTML5 API then in some cases they will (not that the Cordova plugin is running through the browser, there is just also a HTML5 API available that uses the same syntax, so you don’t run into errors). So, if a HTML5 API is available it should work fine when running using ionic serve

If you can provide some more details we might be able to help more easily.

just an empty new app with a cordova plugin: I’ve added the cordova-plugin-file plugin and a 2 “debugger” inside initializeApp

  initializeApp() {
    debugger;  // 1
    // console.log(cordova.file);
    this.platform.ready().then(() => {
      window.addEventListener('filePluginIsReady', () => {
        console.log('File plugin is ready');
        debugger; // 2
        console.log(cordova.file);
      }, false);
  1. doing ionic serve in the debugger 1 , cordova is not defined as the plugin is not loaded and therefore it will never stop in the debugger 2.
  • doing ionic run browser the plugin is loaded and therefore you can see cordova.file defined in the debugger 1. You can also see the app stoping in debugger 2 as expected. The only problem is that after applying changes to a .ts (or .js) file, I need to stop it and run it again (10 to 15 seconds).

So the second method (ionic run browser) would be perfect if it would be clever as the method 1 (ionic serve) and build only what needed in real time.

edit: I’vw wrote a quick workaorund in https://github.com/driftyco/ionic-cli/issues/790: After changing a file, wait until when the console shows the file changed and then:
rsync -rtv www/ platforms/browser/www

1 Like

We are creating the Mobile Applications so when you add the any cordova plug in check in mobile not in broewser

Thank you