Skip to content

Commit db64982

Browse files
committed
refactor: move code
1 parent 2310442 commit db64982

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

packages/plugin-rsc/src/plugin.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -938,17 +938,6 @@ function hashString(v: string) {
938938
return createHash('sha256').update(v).digest().toString('hex').slice(0, 12)
939939
}
940940

941-
function normalizeReferenceId(id: string, name: 'client' | 'rsc') {
942-
if (!server) {
943-
return hashString(path.relative(config.root, id))
944-
}
945-
946-
// align with how Vite import analysis would rewrite id
947-
// to avoid double modules on browser and ssr.
948-
const environment = server.environments[name]!
949-
return normalizeViteImportAnalysisUrl(environment, id)
950-
}
951-
952941
function vitePluginUseClient(
953942
useClientPluginOptions: Pick<
954943
RscPluginOptions,
@@ -1243,7 +1232,14 @@ function vitePluginUseServer(
12431232
// module identity of `import(id)` like browser, so we simply strip it off.
12441233
id = id.split('?v=')[0]!
12451234
}
1246-
normalizedId_ = normalizeReferenceId(id, 'rsc')
1235+
if (config.command === 'build') {
1236+
normalizedId_ = hashString(path.relative(config.root, id))
1237+
} else {
1238+
normalizedId_ = normalizeViteImportAnalysisUrl(
1239+
server.environments.rsc!,
1240+
id,
1241+
)
1242+
}
12471243
}
12481244
return normalizedId_
12491245
}

0 commit comments

Comments
 (0)