@@ -133,12 +133,12 @@ export type RscPluginOptions = {
133133 useBuildAppHook ?: boolean
134134
135135 /**
136- * This allows configuring `react-server` condition environment.
136+ * Custom environment configuration
137137 * @experimental
138- * @default { server: [ 'rsc'] }
138+ * @default { serverEnvironmentName: 'rsc' }
139139 */
140140 environment ?: {
141- server ?: string [ ]
141+ serverEnvironmentName ?: string
142142 }
143143}
144144
@@ -974,16 +974,14 @@ export function vitePluginUseClient(
974974 // https://github.com/vitejs/vite/blob/4bcf45863b5f46aa2b41f261283d08f12d3e8675/packages/vite/src/node/utils.ts#L175
975975 const bareImportRE = / ^ (? ! [ a - z A - Z ] : ) [ \w @ ] (? ! .* : \/ \/ ) /
976976
977- const serverEnvironments = useClientPluginOptions . environment ?. server ?? [
978- 'rsc' ,
979- ]
980- const isServer = ( name : string ) => serverEnvironments . includes ( name )
977+ const serverEnvironmentName =
978+ useClientPluginOptions . environment ?. serverEnvironmentName ?? 'rsc'
981979
982980 return [
983981 {
984982 name : 'rsc:use-client' ,
985983 async transform ( code , id ) {
986- if ( ! isServer ( this . environment . name ) ) return
984+ if ( this . environment . name !== serverEnvironmentName ) return
987985 if ( ! code . includes ( 'use client' ) ) return
988986
989987 const ast = await parseAstAsync ( code )
@@ -1106,7 +1104,7 @@ export function vitePluginUseClient(
11061104 id . startsWith ( '\0virtual:vite-rsc/client-in-server-package-proxy/' )
11071105 ) {
11081106 assert . equal ( this . environment . mode , 'dev' )
1109- assert ( ! isServer ( this . environment . name ) )
1107+ assert ( this . environment . name !== serverEnvironmentName )
11101108 id = decodeURIComponent (
11111109 id . slice (
11121110 '\0virtual:vite-rsc/client-in-server-package-proxy/' . length ,
@@ -1126,7 +1124,10 @@ export function vitePluginUseClient(
11261124 resolveId : {
11271125 order : 'pre' ,
11281126 async handler ( source , importer , options ) {
1129- if ( isServer ( this . environment . name ) && bareImportRE . test ( source ) ) {
1127+ if (
1128+ this . environment . name === serverEnvironmentName &&
1129+ bareImportRE . test ( source )
1130+ ) {
11301131 const resolved = await this . resolve ( source , importer , options )
11311132 if ( resolved && resolved . id . includes ( '/node_modules/' ) ) {
11321133 packageSources . set ( resolved . id , source )
@@ -1151,7 +1152,7 @@ export function vitePluginUseClient(
11511152 }
11521153 } ,
11531154 generateBundle ( _options , bundle ) {
1154- if ( ! isServer ( this . environment . name ) ) return
1155+ if ( this . environment . name !== serverEnvironmentName ) return
11551156
11561157 // track used exports of client references in rsc build
11571158 // to tree shake unused exports in browser and ssr build
@@ -1182,16 +1183,14 @@ export function vitePluginDefineEncryptionKey(
11821183 const KEY_PLACEHOLDER = '__vite_rsc_define_encryption_key'
11831184 const KEY_FILE = '__vite_rsc_encryption_key.js'
11841185
1185- const serverEnvironments = useServerPluginOptions . environment ?. server ?? [
1186- 'rsc' ,
1187- ]
1188- const isServer = ( name : string ) => serverEnvironments . includes ( name )
1186+ const serverEnvironmentName =
1187+ useServerPluginOptions . environment ?. serverEnvironmentName ?? 'rsc'
11891188
11901189 return [
11911190 {
11921191 name : 'rsc:encryption-key' ,
11931192 async configEnvironment ( name , _config , env ) {
1194- if ( isServer ( name ) && ! env . isPreview ) {
1193+ if ( name === serverEnvironmentName && ! env . isPreview ) {
11951194 defineEncryptionKey =
11961195 useServerPluginOptions . defineEncryptionKey ??
11971196 JSON . stringify ( toBase64 ( await generateEncryptionKey ( ) ) )
@@ -1245,10 +1244,8 @@ export function vitePluginUseServer(
12451244 'ignoredPackageWarnings' | 'enableActionEncryption' | 'environment'
12461245 > ,
12471246) : Plugin [ ] {
1248- const serverEnvironments = useServerPluginOptions . environment ?. server ?? [
1249- 'rsc' ,
1250- ]
1251- const isServer = ( name : string ) => serverEnvironments . includes ( name )
1247+ const serverEnvironmentName =
1248+ useServerPluginOptions . environment ?. serverEnvironmentName ?? 'rsc'
12521249
12531250 return [
12541251 {
@@ -1278,13 +1275,12 @@ export function vitePluginUseServer(
12781275 // module identity of `import(id)` like browser, so we simply strip it off.
12791276 id = id . split ( '?v=' ) [ 0 ] !
12801277 }
1281- // TODO
1282- normalizedId_ = normalizeReferenceId ( id , serverEnvironments [ 0 ] ! )
1278+ normalizedId_ = normalizeReferenceId ( id , serverEnvironmentName )
12831279 }
12841280 return normalizedId_
12851281 }
12861282
1287- if ( isServer ( this . environment . name ) ) {
1283+ if ( this . environment . name === serverEnvironmentName ) {
12881284 const transformServerActionServer_ = withRollupError (
12891285 this ,
12901286 transformServerActionServer ,
0 commit comments