get-page-files.ts 687 字节
Newer Older
T
Tim Neutkens 已提交
1
import { normalizePagePath } from './normalize-page-path'
2

3
export type BuildManifest = {
4
  devFiles: string[]
5
  lowPriorityFiles: string[]
6
  pages: {
7
    '/_app': string[]
8 9
    [page: string]: string[]
  }
10 11
}

12 13 14 15
export function getPageFiles(
  buildManifest: BuildManifest,
  page: string
): string[] {
16
  const normalizedPage = normalizePagePath(page)
17 18 19 20 21
  let files = buildManifest.pages[normalizedPage]

  if (!files) {
    files = buildManifest.pages[normalizedPage.replace(/\/index$/, '') || '/']
  }
22 23

  if (!files) {
24
    // tslint:disable-next-line
25 26 27
    console.warn(
      `Could not find files for ${normalizedPage} in .next/build-manifest.json`
    )
28 29 30 31 32
    return []
  }

  return files
}