voidzero-dev / voidzero-dev/vite-plus

Native dev/watch mode support for pure backend (Node.js) applications

Offen
#1,117 5 Kommentare 6 Reaktionen 1 zugewiesene Person Beansprucht von @cpojer Auf GitHub ansehen
pending triage
Vorherrschende Sprache
Rust
Sterne
5.8k
Forks
262
Ø Merge
23 Std. 41 Min.
Gemergte PRs (30 T.)
138

Beschreibung

### Description

Currently, `vite` and `vite-plus` are heavily tailored toward Frontend and SSR development. When trying to use `vite-plus` to build and serve a pure Node.js backend in watch mode, the developer experience feels hacky.

Running `vp dev` automatically starts a frontend server on port `5173`, which is completely unnecessary for a pure backend project. Setting up a proper development environment requires relying on manual workarounds to build, watch, and restart the Node process.

Additionally, combining certain build options for backend targets seems to break Vite-specific features. For example, `import.meta.glob` is not converted before being executed by Node, resulting in runtime errors.

### Suggested solution

It would be incredibly helpful to have first-class, native support for running pure backend applications in watch mode without the frontend/SSR overhead. Ideally:
1. A dedicated command or configuration option (e.g., a pure Node target) that watches and automatically restarts the backend process on file changes, bypassing the `5173` dev server.
2. Proper resolution and conversion of Vite-specific functions like `import.meta.glob` when building for pure Node environments.
3. The ability to natively choose or configure the runtime (e.g., using Node's native type stripping vs. full TypeScript compilation) to execute `.ts` files seamlessly.

*(Note: As mentioned in the Discord thread by @TheAlexLichter, I understand that managed runtimes like Deno/Bun are not planned for support, so this request is primarily focused on Node.js).*

### Alternative

Currently, there are different workarounds to achieve this but they feel hacky:

**Workaround 1 (using `RolldownWatcher`):**
Bypassing the default dev server entirely by writing a custom dev script (`vp run dev`) that invokes Vite's build API in watch mode (`watch: {}`). We then cast the return value to a `RolldownWatcher` and manually manage the server lifecycle:
* Listen to the `event` listener.
* On `START` and `ERROR`: Log the build state.
* On `END`: Run a `restartServer` function that kills the existing child process and uses `spawn` to start a fresh Node process pointing to the newly bundled `dist/main.js`.
* Wire up `SIGINT` and `SIGTERM` listeners to ensure the active server process and watcher gracefully shut down when the terminal is killed.

**Workaround 2 (using `vp pack`):**
Using `vp pack` combined with the `onSuccess` callback to manually kick off the Node.js server. While functional, it feels dirty and misaligned with standard Vite workflows.

### Additional context

This issue stems from a discussion in the Vite Plus Discord regarding the friction of using the toolchain for backend-only projects.

### Validations

- [x] Read the [Contributing Guidelines](https://github.com/voidzero-dev/vite-plus/blob/main/CONTRIBUTING.md).
- [x] Confirm this request is for Vite+ itself and not for Vite, Vitest, tsdown, Rolldown, or Oxc.
- [x] Check that there isn't already an issue requesting the same feature.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.