Skip to content

feat: add vite support#14398

Draft
janvennemann wants to merge 5 commits intotidev:mainfrom
janvennemann:vite
Draft

feat: add vite support#14398
janvennemann wants to merge 5 commits intotidev:mainfrom
janvennemann:vite

Conversation

@janvennemann
Copy link
Copy Markdown
Contributor

Summary

I'm opening this as a draft for now since this involves changes across multiple other projects that need to be released first.

  • Add Vite as a supported JS bundler alongside the existing Webpack integration
  • Add a new ti serve command that starts a Vite dev server and launches the app, enabling HMR-based development
  • Skip full rebuilds when serve metadata (tiapp.xml, target, server config) hasn't changed, reusing previous build artifacts instead
  • Extract platform launcher logic (Android emulator/device, iOS simulator/device/macOS) from inline hook callbacks into reusable modules for both build and serve commands

Changes

New ti serve command (cli/commands/serve.js)

Orchestrates the Vite dev server lifecycle: starts the server, runs a build (or skips it if artifacts are fresh), then launches the app on the target platform using the extracted launchers.

Vite build hook (cli/hooks/vite.js)

Mirrors the existing Webpack hook pattern. Detects Vite in project dependencies, sets builder.useBundler = true, and runs a one-shot Vite build during build.pre.compile (skipped during serve since the dev server is already running).

Shared Vite utilities (cli/lib/vite-utils.js)

Resolves the project-local Vite installation, finds config files, and provides the tiBridgePlugin/createTiViteBridge helpers used by both the build hook and serve command.

Serve helpers (cli/lib/serve/)

  • start-server.js — bootstraps the Vite dev server with HMR configuration
  • metadata.js — content-hash based staleness check for build artifact reuse
  • resolve-host.js — picks the first non-internal IPv4 address for the dev server

Platform launcher extraction

  • Android: android/cli/lib/launcher.js — extracted from android/cli/hooks/run.js
  • iOS device: iphone/cli/lib/device-installer.js — extracted from iphone/cli/hooks/install.js
  • iOS simulator/macOS: iphone/cli/lib/simulator-launcher.js — extracted from iphone/cli/hooks/run.js
  • Fixes command injection in the macOS launcher (execexecFile)

Build command updates

  • Renamed useWebpackuseBundler across Android/iOS build commands and ProcessJsTask
  • Exported builder instance from both platform _build.js files so serve can access builder state

- Fix command injection via exec() in simulator-launcher (use execFile)
- Fix silent device detection failure in device-installer
- Extract shared Vite helpers into cli/lib/vite-utils.js
- Replace promisify with manual wrapper for CLI callback convention
- Close Vite dev server on error, log errors before finishing
- Make metadata write failure non-fatal
- Distinguish ENOENT from other errors in readServeMetadata
- Handle non-Error truthy values in invokeLauncherStep
- Add port conflict guidance in start-server
- Initialize tiSymbols as {} to match object consumption pattern
- Extract DEFAULT_PORT constant, simplify port callback
@cb1kenobi
Copy link
Copy Markdown
Contributor

Neat! I need some time to review. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants