How to configure Ionic for serving PWA from subdirectory, but Android/iOS from root?

I’m trying to configure my Ionic React app to serve the PWA from a subdirectory without affecting the iOS/Android apps.

To serve the PWA from a subdirectory, in package.json, I can change homepage: "/"," to homepage: “subdirectory”,`; then, if I build the PWA, the URLs will be correct.

However, with homepage: "subdirectory",, if I build an Android or Ionic app, I get stuck on the splash screen because it can’t find any of the files.

How can I tell Ionic React that I want to use a different homepage value only for the PWA?

I found this Stack Overflow question, but the answers described there don’t work for Ionic.

Using homepage: '.', causes the PWA to fail to load, and it isn’t possible to specify an absolute URL for capacitor because the PWA, android, and iOS all have different base URLs.

Ok, here is one way to do it: serve PWA from subdirectory on web server, but also build mobile apps.


"homepage": "/subdirectory",

Then, to build, for the PWA, use ionic build.

For the mobile apps, use PUBLIC_URL=/ ionic build.