-
Notifications
You must be signed in to change notification settings - Fork 126
Description
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:
- 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
5173dev server. - Proper resolution and conversion of Vite-specific functions like
import.meta.globwhen building for pure Node environments. - The ability to natively choose or configure the runtime (e.g., using Node's native type stripping vs. full TypeScript compilation) to execute
.tsfiles 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
eventlistener. - On
STARTandERROR: Log the build state. - On
END: Run arestartServerfunction that kills the existing child process and usesspawnto start a fresh Node process pointing to the newly bundleddist/main.js. - Wire up
SIGINTandSIGTERMlisteners 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
- Read the Contributing Guidelines.
- Confirm this request is for Vite+ itself and not for Vite, Vitest, tsdown, Rolldown, or Oxc.
- Check that there isn't already an issue requesting the same feature.
Metadata
Metadata
Assignees
Labels
Type
Fields
Give feedbackPriority
Start date
Target date
Effort