UNPKG

@vitejs/plugin-rsc

Version:
118 lines (117 loc) 4.28 kB
import MagicString from "magic-string"; import { Plugin, ViteDevServer, parseAstAsync } from "vite"; import { Program } from "estree"; //#region src/transforms/wrap-export.d.ts type ExportMeta = { declName?: string; isFunction?: boolean; defaultExportIdentifierName?: string; }; type TransformWrapExportFilter = (name: string, meta: ExportMeta) => boolean; //#endregion //#region src/plugin.d.ts type RscPluginOptions = { /** * shorthand for configuring `environments.(name).build.rollupOptions.input.index` */ entries?: Partial<Record<"client" | "ssr" | "rsc", string>>; /** @deprecated use `serverHandler: false` */ disableServerHandler?: boolean; /** @default { enviornmentName: "rsc", entryName: "index" } */ serverHandler?: { environmentName: string; entryName: string; } | false; /** @default false */ loadModuleDevProxy?: boolean; rscCssTransform?: false | { filter?: (id: string) => boolean; }; ignoredPackageWarnings?: (string | RegExp)[]; /** * 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 false */ useBuildAppHook?: boolean; /** * Custom environment configuration * @experimental * @default { browser: 'client', ssr: 'ssr', rsc: 'rsc' } */ environment?: { browser?: string; ssr?: string; rsc?: string; }; }; /** @experimental */ declare function vitePluginRscMinimal(rscPluginOptions?: RscPluginOptions): Plugin[]; 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 vitePluginFindSourceMapURL(): Plugin[]; declare function findSourceMapURL(server: ViteDevServer, filename: string, environmentName: string): Promise<object | undefined>; declare function vitePluginRscCss(rscCssOptions?: Pick<RscPluginOptions, "rscCssTransform">): Plugin[]; declare function transformRscCssExport(options: { ast: Awaited<ReturnType<typeof parseAstAsync>>; code: string; id?: string; filter: TransformWrapExportFilter; }): Promise<{ output: MagicString; } | undefined>; /** * temporary workaround for * - https://github.com/cloudflare/workers-sdk/issues/9538 (fixed in @cloudflare/vite-plugin@1.8.0) * - https://github.com/vitejs/vite/pull/20077 (fixed in vite@7.0.0) */ declare function __fix_cloudflare(): Plugin; //#endregion export { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginOptions, __fix_cloudflare, findSourceMapURL, transformRscCssExport, vitePluginFindSourceMapURL, vitePluginRsc, vitePluginRscCss, vitePluginRscMinimal };