Skip to content

Create only a single Vite server even if browser mode is enabled #6912

@sheremet-va

Description

@sheremet-va

Describe the bug

Currently, we need to create a server for every workspace project to resolve the config and have access to the module graph for project.vitenode/project.runner properties.

When the browser mode is enabled, we need a separate Vite server because it shouldn't share the same plugin that the project has and needs special additional handling. We also don't want to mix module graphs of different environments.

image

To fix this, we need to make some changes.

  1. refactor: deprecate environmentMatchGlobs and poolMatchGlobs in favor of workspace #6922 aso they can be removed in a major
  2. Remove poolMatchGlob - this makes it possible to run Node.js tests and browser tests in the same project (which is the main reason why we need separate servers). Recommend the workspace instead
  3. Remove environmentMatchGlob - the presence of this requires us to share the module graph between different environments. Recommend the workspace instead
  4. Allow inline workspace #6913 to make the migration easier

This would guarantee that a single project is responsible for a single environment. With Vite 6, we can even migrate it to inline Vite environments.

Possible problems:

  1. --project filter is applied after all projects are resolved. Ideally, we should have a separation between config resolution and server creation, but Vite currently doesn't allow it (environment API allows it though)
  2. --project filter can be changed dynamically in watch mode. To support this, we would have to keep the configs around, but also close the filtered projects, - a lot of moving parts there. I am not sure it's justifyable to keep this feature.
  3. How does inline workspace look like? What if there is a workspace file? Does it override it?

Reproduction

https://github.com/vitest-dev/vitest/tree/main/examples/lit

System Info

Any

Used Package Manager

npm

Validations

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-significantHigh priority enhancement (priority)

    Type

    No type

    Projects

    Status

    Approved

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions