Skip to content

Commit

Permalink
docs(backend-integration): add an example importedChunks (#1634)
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-es authored Oct 20, 2024
1 parent 0dd83ff commit 077ae9c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions guide/backend-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,37 @@
<!-- オプション -->
<link rel="modulepreload" href="assets/shared-B7PI925R.js" />
```

::: details `importedChunks` の疑似実装
TypeScript での `importedChunks` の疑似実装の例(これは、プログラミング言語とテンプレート言語に合わせて調整する必要があります):

```ts
import type { Manifest, ManifestChunk } from 'vite'
export default function importedChunks(
manifest: Manifest,
name: string,
): ManifestChunk[] {
const seen = new Set<string>()
function getImportedChunks(chunk: ManifestChunk): ManifestChunk[] {
const chunks: ManifestChunk[] = []
for (const file of chunk.imports ?? []) {
const importee = manifest[file]
if (seen.has(file)) {
continue
}
seen.add(file)
chunks.push(...getImportedChunks(importee))
chunks.push(importee)
}
return chunks
}
return getImportedChunks(manifest[name])
}
```

:::

0 comments on commit 077ae9c

Please sign in to comment.