Skip to content

Commit

Permalink
Improve Build Output for SSG
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Dec 12, 2019
1 parent 867c459 commit d700575
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
18 changes: 12 additions & 6 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ export default async function build(dir: string, conf = null): Promise<void> {
)

let isStatic = false
let isSsg = false
let ssgPageRoutes: string[] | null = null

pagesManifest[page] = bundleRelative.replace(/\\/g, '/')

Expand Down Expand Up @@ -432,25 +434,29 @@ export default async function build(dir: string, conf = null): Promise<void> {

if (result.prerender) {
sprPages.add(page)
isSsg = true

if (result.prerenderRoutes) {
additionalSprPaths.set(page, result.prerenderRoutes)
ssgPageRoutes = result.prerenderRoutes
}
}

if (result.static && customAppGetInitialProps === false) {
} else if (result.static && customAppGetInitialProps === false) {
staticPages.add(page)
isStatic = true
} else if (result.prerender) {
sprPages.add(page)
}
} catch (err) {
if (err.message !== 'INVALID_DEFAULT_EXPORT') throw err
invalidPages.add(page)
}
}

pageInfos.set(page, { size, serverBundle, static: isStatic })
pageInfos.set(page, {
size,
serverBundle,
static: isStatic,
isSsg,
ssgPageRoutes,
})
})
)
staticCheckWorkers.end()
Expand Down
29 changes: 24 additions & 5 deletions packages/next/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export function collectPages(
export interface PageInfo {
isAmp?: boolean
size: number
static?: boolean
static: boolean
isSsg: boolean
ssgPageRoutes: string[] | null
serverBundle: string
}

Expand All @@ -56,8 +58,8 @@ export function printTreeView(
return chalk.red.bold(size)
}

const messages: string[][] = [
['Page', 'Size'].map(entry => chalk.underline(entry)),
const messages: [string, string][] = [
['Page', 'Size'].map(entry => chalk.underline(entry)) as [string, string],
]

list
Expand All @@ -78,7 +80,7 @@ export function printTreeView(
`${symbol} ${
item.startsWith('/_')
? ' '
: pageInfo && pageInfo.static
: pageInfo && (pageInfo.static || pageInfo.isSsg)
? '*'
: serverless
? 'λ'
Expand All @@ -92,11 +94,28 @@ export function printTreeView(
: ''
: '',
])

if (pageInfo && pageInfo.ssgPageRoutes && pageInfo.ssgPageRoutes.length) {
const totalRoutes = pageInfo.ssgPageRoutes.length
const previewPages = totalRoutes === 4 ? 4 : 3
const contSymbol = i === list.length - 1 ? ' ' : '├'

const routes = pageInfo.ssgPageRoutes.slice(0, previewPages)
if (totalRoutes > previewPages) {
const remaining = totalRoutes - previewPages
routes.push(`[+${remaining} more paths]`)
}

routes.forEach((slug, index, { length }) => {
const innerSymbol = index === length - 1 ? '└' : '├'
messages.push([`${contSymbol} ${innerSymbol} ${slug}`, ''])
})
}
})

console.log(
textTable(messages, {
align: ['l', 'l', 'r', 'r'],
align: ['l', 'l'],
stringLength: str => stripAnsi(str).length,
})
)
Expand Down

0 comments on commit d700575

Please sign in to comment.