Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
5ea721ea
Unverified
Commit
5ea721ea
authored
May 14, 2019
by
Joe Haddad
Committed by
GitHub
May 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Redesigned page output (#7324)
* Redesigned page output * Remove old commented out code * right align files
parent
0770470b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
113 deletions
+79
-113
index.ts
packages/next/build/index.ts
+14
-28
utils.ts
packages/next/build/utils.ts
+65
-85
No files found.
packages/next/build/index.ts
View file @
5ea721ea
...
...
@@ -19,9 +19,10 @@ import {
collectPages
,
getCacheIdentifier
,
getFileForPage
,
getPage
Info
,
getPage
SizeInKb
,
getSpecifiedPages
,
printTreeView
,
PageInfo
,
}
from
'./utils'
import
getBaseWebpackConfig
from
'./webpack-config'
import
{
...
...
@@ -238,43 +239,28 @@ export default async function build(dir: string, conf = null): Promise<void> {
console
.
log
(
chalk
.
green
(
'Compiled successfully.
\
n'
))
}
const
pageInfos
=
new
Map
()
const
pageInfos
=
new
Map
<
string
,
PageInfo
>
()
const
distPath
=
path
.
join
(
dir
,
config
.
distDir
)
le
t
pageKeys
=
Object
.
keys
(
mappedPages
)
cons
t
pageKeys
=
Object
.
keys
(
mappedPages
)
for
(
const
page
of
pageKeys
)
{
const
chunks
=
getPageChunks
(
page
)
const
actualPage
=
page
===
'/'
?
'index'
:
page
const
info
=
await
getPageInfo
(
actualPage
,
distPath
,
buildId
,
false
,
config
.
target
===
'serverless'
)
pageInfos
.
set
(
page
,
{
...(
info
||
{}),
chunks
,
})
if
(
!
(
typeof
info
.
serverSize
===
'number'
))
{
pageKeys
=
pageKeys
.
filter
(
pg
=>
pg
!==
page
)
}
const
actualPage
=
page
===
'/'
?
'/index'
:
page
const
size
=
await
getPageSizeInKb
(
actualPage
,
distPath
,
buildId
)
pageInfos
.
set
(
page
,
{
size
,
chunks
})
}
if
(
Array
.
isArray
(
configs
[
0
].
plugins
))
{
configs
[
0
].
plugins
.
some
((
plugin
:
any
)
=>
{
if
(
plugin
.
ampPages
)
{
plugin
.
ampPages
.
forEach
((
pg
:
any
)
=>
{
const
info
=
pageInfos
.
get
(
pg
)
if
(
info
)
{
info
.
ampOnly
=
true
pageInfos
.
set
(
pg
,
info
)
}
})
if
(
!
plugin
.
ampPages
)
{
return
false
}
return
Boolean
(
plugin
.
ampPages
)
plugin
.
ampPages
.
forEach
((
pg
:
any
)
=>
{
pageInfos
.
get
(
pg
)
!
.
isAmp
=
true
})
return
true
})
}
...
...
packages/next/build/utils.ts
View file @
5ea721ea
import
chalk
from
'chalk'
import
crypto
from
'crypto'
import
findUp
from
'find-up'
import
fs
from
'fs'
import
textTable
from
'next/dist/compiled/text-table'
import
path
from
'path'
import
stripAnsi
from
'strip-ansi'
import
{
promisify
}
from
'util'
import
prettyBytes
from
'../lib/pretty-bytes'
import
{
recursiveReadDir
}
from
'../lib/recursive-readdir'
import
{
getPageChunks
}
from
'./webpack/plugins/chunk-graph-plugin'
const
fsStat
=
promisify
(
fs
.
stat
)
const
fsExists
=
promisify
(
fs
.
exists
)
...
...
@@ -20,78 +25,70 @@ export function collectPages(
)
}
interface
ChunksItem
{
external
:
Set
<
string
>
,
internal
:
Set
<
string
>
}
interface
PageInfo
{
ampOnly
:
boolean
,
serverSize
:
number
,
clientSize
:
number
,
chunks
:
ChunksItem
export
interface
PageInfo
{
isAmp
?:
boolean
size
:
number
chunks
?:
ReturnType
<
typeof
getPageChunks
>
}
export
function
printTreeView
(
list
:
string
[],
pageInfos
:
Map
<
string
,
PageInfo
>
)
{
/*
red for >250kb
yellow for >100kb
green for <100kb
*/
const
getSizeColor
=
(
size
:
number
):
string
=>
{
if
(
size
<
100
*
1000
)
return
'
\
x1b[32m'
if
(
size
<
250
*
1000
)
return
'
\
x1b[33m'
return
'
\
x1b[31m'
export
function
printTreeView
(
list
:
string
[],
pageInfos
:
Map
<
string
,
PageInfo
>
)
{
const
getPrettySize
=
(
_size
:
number
):
string
=>
{
const
size
=
prettyBytes
(
_size
)
// green for 0-100kb
if
(
_size
<
100
*
1000
)
return
chalk
.
green
(
size
)
// yellow for 100-250kb
if
(
_size
<
250
*
1000
)
return
chalk
.
yellow
(
size
)
// red for >= 250kb
return
chalk
.
red
.
bold
(
size
)
}
const
messages
:
string
[][]
=
[
[
'Page'
,
'Size'
,
'Files'
,
'Packages'
].
map
(
entry
=>
chalk
.
underline
(
entry
)),
]
list
.
sort
((
a
,
b
)
=>
(
a
>
b
?
1
:
-
1
))
.
sort
((
a
,
b
)
=>
a
.
localeCompare
(
b
))
.
forEach
((
item
,
i
)
=>
{
const
info
=
pageInfos
.
get
(
item
)
let
numExternal
let
numInternal
let
serverSize
let
clientSize
let
isAmp
if
(
info
)
{
isAmp
=
info
.
ampOnly
serverSize
=
info
.
serverSize
clientSize
=
info
.
clientSize
if
(
info
.
chunks
)
{
const
{
chunks
}
=
info
numExternal
=
chunks
.
external
.
size
numInternal
=
chunks
.
internal
.
size
}
}
const
corner
=
const
symbol
=
i
===
0
?
list
.
length
===
1
?
'─'
:
'┌'
:
i
===
list
.
length
-
1
?
'└'
:
'├'
console
.
log
(
` \x1b[90m
${
corner
}
\x1b[39m
${
item
}${
isAmp
?
' (AMP)'
:
''
}
`
)
if
(
typeof
numExternal
===
'number'
)
{
console
.
log
(
` \x1b[90m| \x1b[39mPackages:
${
numExternal
}
Local modules:
${
numInternal
}
`
);
}
let
sizes
=
'
\
x1b[90m|'
if
(
typeof
serverSize
===
'number'
)
{
sizes
+=
getSizeColor
(
serverSize
)
+
` Server size:
${
prettyBytes
(
serverSize
)}
`
}
if
(
typeof
clientSize
===
'number'
)
{
sizes
+=
getSizeColor
(
clientSize
)
+
` Client size:
${
prettyBytes
(
clientSize
)}
`
}
const
pageInfo
=
pageInfos
.
get
(
item
)
messages
.
push
([
`
${
symbol
}
${
item
}
`
,
...(
pageInfo
?
[
pageInfo
.
isAmp
?
chalk
.
cyan
(
'AMP'
)
:
pageInfo
.
size
>=
0
?
getPrettySize
(
pageInfo
.
size
)
:
'N/A'
,
pageInfo
.
chunks
?
pageInfo
.
chunks
.
internal
.
size
.
toString
()
:
'N/A'
,
pageInfo
.
chunks
?
pageInfo
.
chunks
.
external
.
size
.
toString
()
:
'N/A'
,
]
:
[
''
,
''
,
''
]),
])
})
if
(
sizes
)
console
.
log
(
sizes
)
console
.
log
(
` \x1b[90m
${
i
===
list
.
length
-
1
?
'└'
:
'|'
}
`
);
console
.
log
(
textTable
(
messages
,
{
align
:
[
'l'
,
'l'
,
'r'
,
'r'
],
stringLength
:
str
=>
stripAnsi
(
str
).
length
,
})
)
console
.
log
()
}
...
...
@@ -209,35 +206,18 @@ export async function getCacheIdentifier({
.
digest
(
'hex'
)
}
export
async
function
getPage
Info
(
export
async
function
getPage
SizeInKb
(
page
:
string
,
distPath
:
string
,
buildId
:
string
,
dev
:
boolean
,
serverless
?:
boolean
,
)
{
const
info
:
any
=
{}
const
staticPath
=
dev
?
'development'
:
buildId
buildId
:
string
):
Promise
<
number
>
{
const
clientBundle
=
path
.
join
(
distPath
,
`static/
${
staticPath
}
/pages/`
,
`
${
page
}
.js`
distPath
,
`static/
${
buildId
}
/pages/`
,
`
${
page
}
.js`
)
const
serverPath
=
serverless
?
path
.
join
(
distPath
,
'serverless/pages'
)
:
path
.
join
(
distPath
,
'server/static'
,
staticPath
,
'pages'
)
const
serverBundle
=
path
.
join
(
serverPath
,
`
${
page
}
.js`
)
info
.
clientBundle
=
clientBundle
if
(
!
dev
)
{
try
{
info
.
serverSize
=
(
await
fsStat
(
serverBundle
)).
size
}
catch
(
_
)
{}
try
{
info
.
clientSize
=
(
await
fsStat
(
clientBundle
)).
size
}
catch
(
_
)
{}
}
if
(
page
.
match
(
/
(
_app|_error|_document
)
/
))
return
info
return
info
try
{
return
(
await
fsStat
(
clientBundle
)).
size
}
catch
(
_
)
{}
return
-
1
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment