ionic serve doesn't support cordova browser plugins
Some (but not all) cordova plugins have Javascript proxies if the features they offer can also be used in a regular browser.
I'm using one such plugin and I need to access the cordova.plugins.____ object. However, the cordova.js file is a 404 when using ionic serve. It's not a 404 when using ionic build browser.
How do you access the cordova object in javascript when using ionic serve? Or do you have to ionic build browser every single time you want to see your changes?
+1 Same here
After inspecting my node_modules/@ionic/app-scripts/dist/serve.js
I've managed to come up with this change in the package.json's npm script for ionic:serve =>
"ionic:serve": "ionic-app-scripts serve --iscordovaserve --wwwDir platforms/browser/www/ --buildDir platforms/browser/www/build"
This makes my ionic serve use the browser platform as it's basis and all the good stuff is there provided by serve out of the box (all that I need anyway, didn't check everything).
My only issue at present is kind of unrelated, the splash screen plugin requests img/logo.png while this doesn't seem to exist under my root www of platforms/browser/www/.
My logo.png is in the src/assets directory, it would be cool if that got copied over but this may very well be a splash screen plugin issue instead of something to be done on ionic's side.
At the meantime you can use the following in order to use cordova contacts plugin in ionic serve: https://github.com/meirotstein/cordova-plugin-contacts-mock
@petermetz That is a GREAT solution. Working perfectly for me. Thank you!
Slight mod - I like having source maps built:
"ionic:serve": "ionic-app-scripts serve --sourceMap source-map --iscordovaserve --wwwDir platforms/browser/www/ --buildDir platforms/browser/www/build"
@petermetz Epic solution, thank you!
To the unrelated issue img/logo.png 404, I solved it by customizing ionic-app-scripts/config/copy.config.js. You can provide your own copy.config.js:
// <projectRoot>/copy.config.js
const defaultConfig = require('@ionic/app-scripts/config/copy.config');
module.exports = Object.assign({}, defaultConfig, {
copyLogo: {
src: 'platforms/browser/img/logo.png',
dest: '{{WWW}}/img',
},
});
So in your case, you should be able to use {{SRC}}/assets/logo.png as the src.
If you're not already using an extended config like this, note that you also have to add:
// ...
"config": {
"ionic_copy": "copy.config.js"
}
// ...
to your package.json and it works properly from @ionic/app-scripts": "^0.0.48 - other configs work, but a bug specific to copy.config was fixed in this version.
@petermetz your solution won't work when using azure mobile client plugin. anybody has any idea for a workaround?
With ionic 4 this can be done with:
$ ionic cordova build browser
$ ionic serve --cordova --platform browser
see: https://github.com/ionic-team/ionic-cli/issues/3043
Yeah, I think we can close this issue. I think the original request is now fulfilled.
https://github.com/ionic-team/ionic-cli/issues/3043 is for a related feature request.