UNPKG

@vitejs/plugin-rsc

Version:
150 lines (149 loc) 5.11 kB
import { s as TransformWrapExportFilter } from "./index-CFOPl4Gi.js"; import MagicString from "magic-string"; import { Plugin, ResolvedConfig, Rollup, ViteDevServer, parseAstAsync } from "vite"; //#region src/plugin.d.ts type ClientReferenceMeta = { importId: string; referenceKey: string; packageSource?: string; exportNames: string[]; renderedExports: string[]; serverChunk?: string; groupChunkId?: string; }; type ServerRerferenceMeta = { importId: string; referenceKey: string; exportNames: string[]; }; declare class RscPluginManager { server: ViteDevServer; config: ResolvedConfig; rscBundle: Rollup.OutputBundle; buildAssetsManifest: AssetsManifest | undefined; isScanBuild: boolean; clientReferenceMetaMap: Record<string, ClientReferenceMeta>; clientReferenceGroups: Record<string, ClientReferenceMeta[]>; serverReferenceMetaMap: Record<string, ServerRerferenceMeta>; serverResourcesMetaMap: Record<string, { key: string; }>; stabilize(): void; toRelativeId(id: string): string; } type RscPluginOptions = { /** * shorthand for configuring `environments.(name).build.rollupOptions.input.index` */ entries?: Partial<Record<"client" | "ssr" | "rsc", string>>; /** @default { enviornmentName: "rsc", entryName: "index" } */ serverHandler?: { environmentName: string; entryName: string; } | false; /** @default false */ loadModuleDevProxy?: boolean; rscCssTransform?: false | { filter?: (id: string) => boolean; }; /** * This option allows customizing how client build copies assets from server build. * By default, all assets are copied, but frameworks can establish server asset convention * to tighten security using this option. */ copyServerAssetsToClient?: (fileName: string) => boolean; /** * This option allows disabling action closure encryption for debugging purpose. * @default true */ enableActionEncryption?: boolean; /** * By default, the plugin uses a build-time generated encryption key for * "use server" closure argument binding. * This can be overwritten by configuring `defineEncryptionKey` option, * for example, to obtain a key through environment variable during runtime. * cf. https://nextjs.org/docs/app/guides/data-security#overwriting-encryption-keys-advanced */ defineEncryptionKey?: string; /** Escape hatch for Waku's `allowServer` */ keepUseCientProxy?: boolean; /** * Enable build-time validation of 'client-only' and 'server-only' imports * @default true */ validateImports?: boolean; /** * use `Plugin.buildApp` hook (introduced on Vite 7) instead of `builder.buildApp` configuration * for better composability with other plugins. * @default true since Vite 7 */ useBuildAppHook?: boolean; /** * Custom environment configuration * @experimental * @default { browser: 'client', ssr: 'ssr', rsc: 'rsc' } */ environment?: { browser?: string; ssr?: string; rsc?: string; }; /** * Custom chunking strategy for client reference modules. * * This function allows you to group multiple client components into * custom chunks instead of having each module in its own chunk. * By default, client chunks are grouped by `meta.serverChunk`. */ clientChunks?: (meta: { /** client reference module id */ id: string; /** normalized client reference module id */ normalizedId: string; /** server chunk which includes a corresponding client reference proxy module */ serverChunk: string; }) => string | undefined; }; type PluginApi = { manager: RscPluginManager; }; /** @experimental */ declare function getPluginApi(config: Pick<ResolvedConfig, "plugins">): PluginApi | undefined; /** @experimental */ declare function vitePluginRscMinimal(rscPluginOptions?: RscPluginOptions, manager?: RscPluginManager): Plugin[]; declare global { function __VITE_ENVIRONMENT_RUNNER_IMPORT__(environmentName: string, id: string): Promise<any>; } declare function vitePluginRsc(rscPluginOptions?: RscPluginOptions): Plugin[]; declare class RuntimeAsset { runtime: string; constructor(value: string); } type AssetsManifest = { bootstrapScriptContent: string | RuntimeAsset; clientReferenceDeps: Record<string, AssetDeps>; serverResources?: Record<string, Pick<AssetDeps, "css">>; }; type AssetDeps = { js: (string | RuntimeAsset)[]; css: (string | RuntimeAsset)[]; }; type ResolvedAssetsManifest = { bootstrapScriptContent: string; clientReferenceDeps: Record<string, ResolvedAssetDeps>; serverResources?: Record<string, Pick<ResolvedAssetDeps, "css">>; }; type ResolvedAssetDeps = { js: string[]; css: string[]; }; declare function transformRscCssExport(options: { ast: Awaited<ReturnType<typeof parseAstAsync>>; code: string; id?: string; filter: TransformWrapExportFilter; }): Promise<{ output: MagicString; } | undefined>; //#endregion export { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, type RscPluginManager, RscPluginOptions, vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };