Define a server url
I have a Nuxt app in SSR mode, with CapacitorJS. Ultimately after relevant steps, it successfully runs in my Android Studio emulator and on my physical Pixel 2 (manual apk install). I haven't yet fully tested in production or in iOS XCode.
Defining a server URL was the trick. Initially I was wrestling with webdir
like everyone else, although this doesn't seem to be needed if using the server: {url: }
property.
capacitor.config.json:
{
"appId": "io.mysillyapp.app",
"appName": "My Silly App",
"server": {
"url": "https://mysillyapp.myapphosting.io"
},
"linuxAndroidStudioPath": "/snap/bin/android-studio"
}
Optionally wrap in a condition, like so (link):
{
...
server: process.env.HOST ? { url: `${process.env.HOST}:${process.env.PORT ?? 8100 }` : undefined
...
}
After running npx cap copy
, you'll see a warning:
Web asset directory specified by webDir does not exist. This is not an error because server.url is set in config.
If you care about this warning and think you need it, then define webDir
; I have it pointing to .nuxt
:
{
...
"webDir": ".nuxt",
...
}
NOTES:
Capacitor docs for server url
says "This is not intended for use in production" without additional explanation. What does it mean, I don't know. My first thought is they're being conservative here with the presumption that Apple may not like this in an app submission (From a high-level, Apple wants real apps, not websites-wrapped-as-apps).
However, a commenter seems to be successfully using server url
in production, having passed app store submissions.
https://capacitorjs.com/docs/v3/config
/**
* Load an external URL in the Web View.
*
* This is intended for use with live-reload servers.
*
* **This is not intended for use in production.**
*
* @since 1.0.0
*/
url?: string;
webDir
needs to be set as? I've tried setting it to.nuxt
anddist
(which doesn't exist as it's srr) but no luck – Schalles.nuxt
(cache) nordist
(final built directory). – Elmaleh.nuxt
ordist
directory that I am touching, its value ofwebDir
incapacitor.config.json
@MojtabaBarari used to solve the original issue I want to know – Schalles