m0dch3n / vue-cli-plugin-cordova

Vue Cli 3 Cordova Plugin
MIT License
417 stars 63 forks source link

config.xml not loaded by Cordova Plugin when using cordova-serve-browser #97

Closed daviesdoclc closed 4 years ago

daviesdoclc commented 4 years ago

I have a Cordova Plugin (SplashScreen) that is trying to read config.xml during startup to get the PREFERENCES from the configuration. It ends up making an xhr request to /config.xml eventually. However, since I have the vue router installed, that path ends up returning the contents of index.html instead of the config.xml file. How is this suppose to work? I'm running "vue-cli-service cordova-serve-browser". I fear none of the plugins that need to read configuration will work in this workflow. "cordova run browser" works fine from the src-cordova directory. Do I have to map /config.xml somehow?

daviesdoclc commented 4 years ago

Two other notes. If I use http://localhost:8000/config.xml when running as "cordova run browser" it serves up the config.xml. Under "vue-cli-service cordova-serve-browser" it serves up the contents of index.html.

If I copy config.xml to /public (where the index.html is) then it also works (able to read config.xml). My concern is, there may be other files that plugins (and cordova) need to read.

daviesdoclc commented 4 years ago

I'm gonna answer my own question, but I'd still like verification that this is the right approach. If I set the following in vue.config.js

devServer: { contentBase: "src-cordova" }

config.xml resolves properly. Sound ok?

m0dch3n commented 4 years ago

IMO using contentbase is not the best way, because the files under your vue public folder will no longer be served...

And when you build the app, your devserver settings will be ignored and I'm not sure, if cordova is copying the config.xml to your file:///android_asset/www/ folder...

But maybe your plugin does this, and that's why it's working with cordova run and cordova build under src-cordova

The difference between cordova run and vue cordova-serve-browser is with the cordova command you don't serve from the vue devserver, but from cordova.

So in order, that your cordova-serve-browser can serve with vue devserver your config.xml, there are 2 solutions

1) Use cordova hooks to copy your config.xml to your vue public folder

https://cordova.apache.org/docs/en/9.x/guide/appdev/hooks/index.html

2) Or add a middleware to the devserver, that serves on the correct url, the config.xml, in my plugin is also an example, which works the cordova.js files

https://github.com/m0dch3n/vue-cli-plugin-cordova/blob/9193bd8ebb48cbd27c103dd56987730ee2e097a5/index.js#L114

daviesdoclc commented 4 years ago

I think contentBase can list multiple sources, so I might also be able to list public. However, I'll look at your other 2 solutions. Thanks! I know this is more of a webpack dev server issue.