Skip to content

Commit

Permalink
Use renderChunk instead of generateBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Jul 1, 2024
1 parent 567e6a6 commit a86b43d
Showing 1 changed file with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,18 @@ export function vitePluginServerIslands({ settings }: { settings: AstroSettings
}
}
},
generateBundle(_options, bundles) {
let mapSource = 'new Map([';
for(let [resolvedPath, referenceId] of referenceIdMap) {
const fileName = this.getFileName(referenceId);
const islandName = settings.serverIslandNameMap.get(resolvedPath)!;
mapSource += `\n\t['${islandName}', () => import('./${fileName}')],`
}
mapSource += '\n]);';
referenceIdMap.clear();

for (const [_fileName, output] of Object.entries(bundles)) {
if(output.type !== 'chunk') continue;

if(output.code.includes(serverIslandPlaceholder)) {
output.code = output.code.replace(serverIslandPlaceholder, mapSource);
renderChunk(code) {
if(code.includes(serverIslandPlaceholder)) {
let mapSource = 'new Map([';
for(let [resolvedPath, referenceId] of referenceIdMap) {
const fileName = this.getFileName(referenceId);
const islandName = settings.serverIslandNameMap.get(resolvedPath)!;
mapSource += `\n\t['${islandName}', () => import('./${fileName}')],`
}
mapSource += '\n]);';
referenceIdMap.clear();
return code.replace(serverIslandPlaceholder, mapSource);
}
}
},
}
}

0 comments on commit a86b43d

Please sign in to comment.