ionic-cli: 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?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 22
- Comments: 48 (2 by maintainers)
Commits related to this issue
- Fix Ionic compilation for browser with Cordova plugins Based on https://github.com/driftyco/ionic-cli/issues/354 — committed to kylemsguy/Vroomy by zhuowei 7 years ago
- Make 'ionic serve' support plugins. Thanks for https://github.com/petermetz for providing this workaround in driftyco/ionic-cli#354! — committed to sth-larp/deus-mobile by aeremin 7 years ago
- Use this workaround to load browser plugins https://github.com/ionic-team/ionic-cli/issues/354#issuecomment-269223842 — committed to razorpay/razorpay-cordova-sample-app by selvagsz 7 years ago
- Ionic3 example (#8) * ionic start rzp-ionic3-example blank --type=ionic-angular * cordova platform add browser/ios/android && cordova plugin add https://github.com/razorpay/razorpay-cordova.git --... — committed to razorpay/razorpay-cordova-sample-app by selvagsz 7 years ago
- Make 'ionic serve' support plugins. Thanks for https://github.com/petermetz for providing this workaround in driftyco/ionic-cli#354! — committed to alice-larp/alice-larp-sdk-deprecated by aeremin 7 years ago
- Make 'ionic serve' support plugins. Thanks for https://github.com/petermetz for providing this workaround in driftyco/ionic-cli#354! — committed to sr-2020/nodejs-monorepo by aeremin 7 years ago
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 ofplatforms/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.
This is really horrible… can you at least throw some log that that’s the problem? Wasted a whole day on this…
At the moment I’m trying to work around this by using the gulp file to process everything for me. I’m still surprised that you can’t use a cordova plugin while developing in browser.
First I manually pulled the
./plugins/name/www/*.js
out and placed them inside./www/plugin/file.js
. This allows me to modify them as I work andionic serve
picks them up. From here, gulp takes over.Then my index.html manually includes
./www/build/cordova.js
which loads the plugins out of./www/build/plugins/...
If anyone has any better ideas please let me know.
What I have done as a hacky workaround for the time being is just do an ionic build browser and then I copy the
platform_www
folder from theplatforms/browser
directory into mywww
folder and then I reference it inside my index.html with<script src="platform_www/cordova.js"></script>
. After doing that my ionic serve will then load all my cordova browser plugins… (Works 90% of the time, i usually just refresh my page if the plugins don’t load on initial startup.)ionic build browser
platforms/browser/platform_www
folder towww
folder<script src="platform_www/cordova.js"></script>
toindex.html
ionic serve
(refresh page if plugins don’t load at first.)Throwing another +1 onto the heap
With ionic 4 this can be done with:
see: https://github.com/ionic-team/ionic-cli/issues/3043
@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"
@LordPrettyFlacko I get that as well but am able to build and serve for browser (pulling in all js and hooks) with
ionic build browser --desktop --testing && http-server platforms/browser/www/
At this moment we solved this issue by generating a Gulp command that serves the
platforms/browser/www
directory. You should manually build for browser each time you make a change (ionic build browser
):+1 Same here
+1
+1 I’m experiencing this issue as well, and it really sucks that
ionic run browser --livereload
does not work either… Is there anyone on the Ionic team that is looking into this?? I haven’t seen anyone from them comment on this yet.Facing the same issue with
ionic serve
. Hope this gets resolved soon.ionic run browser
works for me thoughHello,
I’m new to ionic and it’s been a wonderful experience except for the fact that I lost several hours completely stuck thanks to this issue. The ‘ionic serve’ experience is great and it’s not at all obvious that you don’t have access to cordova plugins, nor to ‘cordova’ itself, in this environment.
Any news (X3) on fixing this? It has caused headaches for lots of people already (cf. https://github.com/Wizcorp/phonegap-facebook-plugin/issues/866, https://github.com/driftyco/ng-cordova/issues/446, http://stackoverflow.com/questions/27906239/facebookconnectplugin-is-not-defined-ngcordova-ionic-app, etc.) and fixing it will be critical to maintaining the otherwise high quality of the ionic experience.
Thank you.