Skip to content

Commit 74f6e62

Browse files
committed
feat(rsc): ability to merge client reference chunks
1 parent 6924db4 commit 74f6e62

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

packages/plugin-rsc/src/plugin.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,12 +1119,30 @@ function vitePluginUseClient(
11191119
const exports = meta.renderedExports
11201120
.map((name) => (name === 'default' ? 'default: _default' : name))
11211121
.sort()
1122-
code += `
1123-
${key}: async () => {
1124-
const {${exports}} = await import(${id});
1125-
return {${exports}};
1126-
},
1127-
`
1122+
if (this.environment.name === 'client') {
1123+
// TODO:
1124+
// - re-export through virtual to fiter renderedExports
1125+
// - replace `import.meta.ROLLUP_FILE_URL_` on our own
1126+
// - handle "vite preload" on our own
1127+
const chunkId = this.emitFile({
1128+
type: 'chunk',
1129+
id: meta.importId,
1130+
preserveSignature: 'allow-extension',
1131+
})
1132+
code += `
1133+
${key}: async () => {
1134+
const {${exports}} = await import(import.meta.ROLLUP_FILE_URL_${chunkId});
1135+
return {${exports}};
1136+
},
1137+
`
1138+
} else {
1139+
code += `
1140+
${key}: async () => {
1141+
const {${exports}} = await import(${id});
1142+
return {${exports}};
1143+
},
1144+
`
1145+
}
11281146
}
11291147
code = `export default {${code}};\n`
11301148
return { code, map: null }

0 commit comments

Comments
 (0)