vite-plugin-react-server
Version:
Vite plugin for React Server Components (RSC)
39 lines • 2.11 kB
TypeScript
import type { Plugin } from "vite";
interface ClientPackagesUserOptions {
clientPackages?: readonly string[];
excludeClientPackages?: readonly string[];
verbose?: boolean;
}
/**
* Vite plugin that runs auto-detection in its async `config` hook, then
* mutates `userOptions.clientPackages` so all downstream consumers (the
* transformer's whitelist filter, `resolveUserConfig`'s noExternal merge)
* see the merged list when their own hooks read it.
*
* Why mutation: the orchestrator passes the same `userOptions` reference
* to every plugin it creates. As long as nobody copies the object on the
* way through, mutating `clientPackages` here is visible in every other
* plugin's hooks. See `createPluginOrchestrator.{server,client}.ts` for
* the comment guarding against accidental spreads.
*
* `enforce: "pre"` puts this plugin's `config` hook ahead of
* `createEnvironmentPlugin`'s, so by the time `resolveUserConfig` reads
* `userOptions.clientPackages` for the noExternal merge, the auto-detected
* packages are already in the list.
*
* Returns a partial Vite config that adds the merged list to the **root**
* `optimizeDeps.exclude`. The per-environment SSR-side exclude in
* `resolveUserConfig` covers `srrConfig.optimizeDeps.exclude` only — that
* never reaches Vite's dev pre-bundler, which reads from the root config.
* Without this, esbuild concatenates every `"use client"` directive out of
* each clientPackage submodule into `node_modules/.vite/deps/<pkg>.js`, the
* server-env module runner consults the same cache when resolving the
* package, and vprs's transformer never sees the directives to convert
* them into `registerClientReference` — a server component importing
* `@chakra-ui/react` (or any other auto-detected client package) then
* crashes the dev server with `react does not provide an export named
* createContext` under the `react-server` condition.
*/
export declare const clientPackagesDiscoveryPlugin: (userOptions: ClientPackagesUserOptions & Record<string, unknown>) => Plugin;
export {};
//# sourceMappingURL=plugin.d.ts.map