Menu

One Vite build, two runtimes: shipping a browser game to the open web and into an offline WebView
📰

One Vite build, two runtimes: shipping a browser game to the open web and into an offline WebView

DEV Community: flutter·Nick.Hu·3 days ago
#quuS5gAl
#devtoflutter#devto#dev#offline#const
Reading 0:00
15s threshold

I shipped ApexDrawn as a plain static site: you draw a closed loop, it becomes a racetrack, and then you drive it. Later I needed a second build target - a mobile shell that loads the same game from local assets with no network at all.

The interesting part wasn't the game logic. It was that the whole app assumed a server: accounts, /api/* for purchases and garage state, a WebSocket relay for races, analytics, payments. None of that can exist in an offline WebView. I didn't want a fork, so the split is one build-time flag and everything else follows from it.

One flag, two bundles

// src/appMode.ts export const OFFLINE_APP = import . meta . env . VITE_OFFLINE_APP === "true" ;

Enter fullscreen mode

Exit fullscreen mode

Because this is a compile-time constant, Rollup tree-shakes the unreachable branch. The offline bundle genuinely contains no auth SDK, no analytics and no checkout code - not "code that checks a boolean at runtime and returns early".…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.