-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capacitor build script fixes #2516
base: main
Are you sure you want to change the base?
Conversation
Changes in `.env.development.local` should override those in `.env`, but this was not working as intended.
Prior to this fix, `yarn cap:android` built a static development version of the app. It builds correctly, but upon opening the app the user just gets a black screen. This was happening because of a line in the Capacitor config file that says to use a development server defined in `.env` instead of loading from local built assets (if `NODE_ENV=development`) So there was an incongruency – `cap:android` is creating a static build, but the Capacitor config is set up to use live server. I have resolved this with some changes in `capacitor.config.ts` and some new scripts in `package.json`: * yarn cap:android:dev – dev build that uses live server * yarn cap:android:static – dev build that uses static assets * yarn cap:android – dev build that uses live server (default) and the same for yarn cap:ios, yarn cap:ios:static, yarn cap:ios:dev. Now all build scripts work as intended.
Set CAPACITOR_SERVER_URL to the default address the dev server runs at (localhost:3000), and guide users to change in .env.development.local if necessary. This enables usage of the dev server directly after cloning without any config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Unfortunately, I now see the blank screen on iOS :). When running yarn cap:ios
on main
the Xcode console says capacitor://localhost
(correct) and on this branch it says http://192.168.1.8:3000/
(incorrect, at least when in development mode).
Aside from that, maybe you can explain more about BUILD_MODE. Our original goal for configuring the build environment was to have everything branch off NODE_ENV
, which can be development
(default), production
, or test
.
It's been a while since another developer set up Capacitor on this project, but it looks like the intention is to serve the app from the vite dev server in development
mode and serve the app from the internal Capacitor sever in production
mode. I suspect the Android issue is actually a problem connecting to localhost
rather than a misconfiguration of the environment per se.
Apologies for the regression! Let me explain the rationale behind these changes. I'll work with a fresh clone of both Evaluating the behaviour in
|
Ah, I see! I misunderstood the localhost part.
Yes, that makes sense.
The static assets that are generated with
I don't think we need to worry about Do you think this would work? Or do you think static/server + production/development are orthogonal? I'm confused about what a dev build of static assets would mean... 🤔
This does not work on my side, and
This works for me! I hadn't tried it before. Are you able to run the Capacitor app against the live dev server? If so, it must be an issue on my computer and I can work on that separately. I'll be interested to see if it works for the developer that's coming in to work on the Capacitor build. |
Okay, I think I can see the confusion! Here's how the Capacitor starter project does it by default.
In the stock config, there isn't even a live server. You get two builds:
Like you pointed out, our static asset development builds contain a production build from vite + development build of the native app. This is an oversight, the builds should be as follows:
I do hear what you're saying – the vite server is more appropriate for actual development. The main advantage behind the static development build is that they'd enable development tools (like web inspect) to attach to the app. That could come in if a dev/tester's using the app away from the computer, they run into a bug, and need the ability to connect up to a computer to investigate more deeply. Of course, we couldn't do this with a production build. I can either:
Hope that makes sense 😅 Aiming to get this closed & merged ASAP so you can hand over to your Capacitor dev.
Yes – this works for me on a fresh clone if I start the vite server in one tab, then run |
Thanks for your response.
My takeaway from this is that the live dev server has different benefits from a static development build, and that these are mutually exclusive:
Is that accurate? I'm a little out of my element here, and I'm not sure what to do. @msdewitt Would you mind taking a look at this discussion and offering your opinion since you're our new Capacitor guy? :)
I'm reluctant to try a fresh clone, as it's a time-consuming process. It's also important to me that I can rely on git for version control and trust that checking out a different version is consistent across platforms. So a fresh clone is not something I typically reach for. But I can try it this time since this appears to only be an issue on my machine. |
It's more like this:
I hope this makes sense. We can just go with a simpler live dev + production build setup, and take static dev build out of the equation if it's making things confusing. Really, the behaviour of the iOS Capacitor build being a "static dev build" prior to my fixes was why I kept it in! Looking forward to yours + @msdewitt's input. |
There were some issues with the Capacitor config file (
capacitor.config.ts
) and the build scripts for Capacitor inpackage.json
that were stopping me from getting a working build of Capacitor on Android. Opening the app would just yield a black screen.This was happening because of a line in the Capacitor config file that says to use a development server defined in
.env
instead of loading from local built assets (ifNODE_ENV=development
)I have resolved this with some changes in
capacitor.config.ts
and some new scripts inpackage.json
:And all the same for iOS.
(As a bonus – this also means we have proper build scripts ready for CI/CD!)