Share services between `nitro/vite` and `nitro/rsbuild`

Open
#5,015 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript, vite

Research direction

Start by comparing entry-server detection in src/build/vite/plugin.ts and src/build/rsbuild/_services.ts, then trace the Vite and Rsbuild runtime and virtual-module paths described in the issue. The proposal is complete when core resolves shared services, both integrations report service loading for development and production, and Rsbuild uses the shared runtime without breaking the Vite alias.

Written by the indexing model from the issue text.

Description

vite

nitro/vite and nitro/rsbuild (#5011) both run server environments as services that Nitro fetches (e.g. ssr), but each one has its own config, runtime API and internals for the same model: a service is an ESM entry exporting fetch, it shares the nitro/* runtime of the server, and its output is bundled by Nitro in production.

Today:

  • Config: vite.services in Vite; nothing in Rsbuild (only target: "node" environments).
  • entry-server detection is duplicated (src/build/vite/plugin.ts, src/build/rsbuild/_services.ts), and only Vite checks that the server entry and the SSR entry differ.
  • Runtime: fetchViteEnv() from nitro/vite/runtime vs fetchRsbuildEnv() from nitro/rsbuild/runtime.
  • Internals: separate services virtual modules (#nitro/virtual/vite-services, #nitro/virtual/rsbuild-services) with the same lazyService code, separate dev globals, and separate default SSR renderer handlers and renderer selection.

Proposal (additive, no breaking change for nitro/vite):

  • Top-level services option ({ [name]: { entry } }), resolved in core with entry-server detection and the entry conflict check. vite.services stays as an alias.
  • The integrations map services to their environments and register auto-detected server environments back, then report how each service output is loaded (dev and prod).
  • Core generates one services virtual module, one SSR renderer handler and the default renderer selection.
  • One runtime API, e.g. fetchService(name, input, init?) from nitro/services. fetchViteEnv() becomes an alias.

nitro/rsbuild would then use these instead of adding fetchRsbuildEnv().

🤖 Generated with AI assistant

Dominant language
TypeScript
Stars
11.5k
Forks
968
Avg merge
4d 9h
Merged PRs (30d)
64

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nitrojs/nitro

All issues in nitrojs/nitro

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.