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
845dc082
Commit
845dc082
authored
Dec 14, 2019
by
Joe Haddad
Committed by
JJ Kasper
Dec 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compute Gzip Sizes of Files (#9745)
parent
9622c655
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
24 deletions
+21
-24
utils.ts
packages/next/build/utils.ts
+17
-21
package.json
packages/next/package.json
+1
-0
yarn.lock
yarn.lock
+3
-3
No files found.
packages/next/build/utils.ts
View file @
845dc082
import
chalk
from
'chalk'
import
chalk
from
'chalk'
import
fs
from
'fs
'
import
gzipSize
from
'gzip-size
'
import
textTable
from
'next/dist/compiled/text-table'
import
textTable
from
'next/dist/compiled/text-table'
import
path
from
'path'
import
path
from
'path'
import
{
isValidElementType
}
from
'react-is'
import
{
isValidElementType
}
from
'react-is'
import
stripAnsi
from
'strip-ansi'
import
stripAnsi
from
'strip-ansi'
import
{
promisify
}
from
'util'
import
{
Redirect
,
Rewrite
}
from
'../lib/check-custom-routes'
import
{
Redirect
,
Rewrite
}
from
'../lib/check-custom-routes'
import
{
SPR_GET_INITIAL_PROPS_CONFLICT
}
from
'../lib/constants'
import
{
SPR_GET_INITIAL_PROPS_CONFLICT
}
from
'../lib/constants'
import
prettyBytes
from
'../lib/pretty-bytes'
import
prettyBytes
from
'../lib/pretty-bytes'
...
@@ -14,14 +13,11 @@ import { getRouteMatcher, getRouteRegex } from '../next-server/lib/router/utils'
...
@@ -14,14 +13,11 @@ import { getRouteMatcher, getRouteRegex } from '../next-server/lib/router/utils'
import
{
isDynamicRoute
}
from
'../next-server/lib/router/utils/is-dynamic'
import
{
isDynamicRoute
}
from
'../next-server/lib/router/utils/is-dynamic'
import
{
findPageFile
}
from
'../server/lib/find-page-file'
import
{
findPageFile
}
from
'../server/lib/find-page-file'
const
fsStatPromise
=
promisify
(
fs
.
stat
)
const
fileGzipStats
:
{
[
k
:
string
]:
Promise
<
number
>
}
=
{}
const
fileStats
:
{
[
k
:
string
]:
Promise
<
fs
.
Stats
>
}
=
{}
const
fsStatGzip
=
(
file
:
string
)
=>
{
const
fsStat
=
(
file
:
string
)
=>
{
if
(
fileGzipStats
[
file
])
return
fileGzipStats
[
file
]
if
(
fileStats
[
file
])
return
fileStats
[
file
]
fileGzipStats
[
file
]
=
gzipSize
.
file
(
file
)
return
fileGzipStats
[
file
]
fileStats
[
file
]
=
fsStatPromise
(
file
)
return
fileStats
[
file
]
}
}
export
function
collectPages
(
export
function
collectPages
(
...
@@ -63,11 +59,11 @@ export async function printTreeView(
...
@@ -63,11 +59,11 @@ export async function printTreeView(
)
{
)
{
const
getPrettySize
=
(
_size
:
number
):
string
=>
{
const
getPrettySize
=
(
_size
:
number
):
string
=>
{
const
size
=
prettyBytes
(
_size
)
const
size
=
prettyBytes
(
_size
)
// green for 0-1
0
0kb
// green for 0-1
3
0kb
if
(
_size
<
1
0
0
*
1000
)
return
chalk
.
green
(
size
)
if
(
_size
<
1
3
0
*
1000
)
return
chalk
.
green
(
size
)
// yellow for 1
00-25
0kb
// yellow for 1
30-17
0kb
if
(
_size
<
25
0
*
1000
)
return
chalk
.
yellow
(
size
)
if
(
_size
<
17
0
*
1000
)
return
chalk
.
yellow
(
size
)
// red for >=
25
0kb
// red for >=
17
0kb
return
chalk
.
red
.
bold
(
size
)
return
chalk
.
red
.
bold
(
size
)
}
}
...
@@ -302,12 +298,12 @@ async function computeFromManifest(
...
@@ -302,12 +298,12 @@ async function computeFromManifest(
.
filter
(([,
len
])
=>
len
===
expected
)
.
filter
(([,
len
])
=>
len
===
expected
)
.
map
(([
f
])
=>
f
)
.
map
(([
f
])
=>
f
)
let
stats
:
[
string
,
fs
.
Stats
][]
let
stats
:
[
string
,
number
][]
try
{
try
{
stats
=
await
Promise
.
all
(
stats
=
await
Promise
.
all
(
commonFiles
.
map
(
commonFiles
.
map
(
async
f
=>
async
f
=>
[
f
,
await
fsStat
(
path
.
join
(
distPath
,
f
))]
as
[
string
,
fs
.
Stats
]
[
f
,
await
fsStat
Gzip
(
path
.
join
(
distPath
,
f
))]
as
[
string
,
number
]
)
)
)
)
}
catch
(
_
)
{
}
catch
(
_
)
{
...
@@ -317,10 +313,10 @@ async function computeFromManifest(
...
@@ -317,10 +313,10 @@ async function computeFromManifest(
lastCompute
=
{
lastCompute
=
{
commonFiles
,
commonFiles
,
sizeCommonFile
:
stats
.
reduce
(
sizeCommonFile
:
stats
.
reduce
(
(
obj
,
n
)
=>
Object
.
assign
(
obj
,
{
[
n
[
0
]]:
n
[
1
]
.
size
}),
(
obj
,
n
)
=>
Object
.
assign
(
obj
,
{
[
n
[
0
]]:
n
[
1
]
}),
{}
{}
),
),
sizeCommonFiles
:
stats
.
reduce
((
size
,
[,
stat
])
=>
size
+
stat
.
size
,
0
),
sizeCommonFiles
:
stats
.
reduce
((
size
,
[,
stat
])
=>
size
+
stat
,
0
),
}
}
cachedBuildManifest
=
manifest
cachedBuildManifest
=
manifest
...
@@ -366,8 +362,8 @@ export async function getPageSizeInKb(
...
@@ -366,8 +362,8 @@ export async function getPageSizeInKb(
deps
.
push
(
clientBundle
)
deps
.
push
(
clientBundle
)
try
{
try
{
let
depStats
=
await
Promise
.
all
(
deps
.
map
(
fsStat
))
let
depStats
=
await
Promise
.
all
(
deps
.
map
(
fsStat
Gzip
))
return
depStats
.
reduce
((
size
,
stat
)
=>
size
+
stat
.
size
,
0
)
return
depStats
.
reduce
((
size
,
stat
)
=>
size
+
stat
,
0
)
}
catch
(
_
)
{}
}
catch
(
_
)
{}
return
-
1
return
-
1
}
}
...
...
packages/next/package.json
View file @
845dc082
...
@@ -95,6 +95,7 @@
...
@@ -95,6 +95,7 @@
"find-up"
:
"4.0.0"
,
"find-up"
:
"4.0.0"
,
"fork-ts-checker-webpack-plugin"
:
"3.1.1"
,
"fork-ts-checker-webpack-plugin"
:
"3.1.1"
,
"fresh"
:
"0.5.2"
,
"fresh"
:
"0.5.2"
,
"gzip-size"
:
"5.1.1"
,
"ignore-loader"
:
"0.1.2"
,
"ignore-loader"
:
"0.1.2"
,
"is-docker"
:
"2.0.0"
,
"is-docker"
:
"2.0.0"
,
"is-wsl"
:
"2.1.1"
,
"is-wsl"
:
"2.1.1"
,
...
...
yarn.lock
View file @
845dc082
...
@@ -4172,7 +4172,7 @@ browserify-zlib@^0.2.0:
...
@@ -4172,7 +4172,7 @@ browserify-zlib@^0.2.0:
dependencies:
dependencies:
pako "~1.0.5"
pako "~1.0.5"
browserslist@^4.0.0, browserslist@^4.3.6, browserslist@^4.6.0, browserslist@^4.6.3, browserslist@^4.6.4, browserslist@^4.7.
1, browserslist@^4.7.
3:
browserslist@^4.0.0, browserslist@^4.3.6, browserslist@^4.6.0, browserslist@^4.6.3, browserslist@^4.6.4, browserslist@^4.7.3:
version "4.8.2"
version "4.8.2"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.8.2.tgz#b45720ad5fbc8713b7253c20766f701c9a694289"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.8.2.tgz#b45720ad5fbc8713b7253c20766f701c9a694289"
integrity sha512-+M4oeaTplPm/f1pXDw84YohEv7B1i/2Aisei8s4s6k3QsoSHa7i5sz8u/cGQkkatCPxMASKxPualR4wwYgVboA==
integrity sha512-+M4oeaTplPm/f1pXDw84YohEv7B1i/2Aisei8s4s6k3QsoSHa7i5sz8u/cGQkkatCPxMASKxPualR4wwYgVboA==
...
@@ -4436,7 +4436,7 @@ caniuse-api@^3.0.0:
...
@@ -4436,7 +4436,7 @@ caniuse-api@^3.0.0:
lodash.memoize "^4.1.2"
lodash.memoize "^4.1.2"
lodash.uniq "^4.5.0"
lodash.uniq "^4.5.0"
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000980, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.300010
02, caniuse-lite@^1.0.300010
10, caniuse-lite@^1.0.30001015:
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000980, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001010, caniuse-lite@^1.0.30001015:
version "1.0.30001015"
version "1.0.30001015"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001015.tgz#15a7ddf66aba786a71d99626bc8f2b91c6f0f5f0"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001015.tgz#15a7ddf66aba786a71d99626bc8f2b91c6f0f5f0"
integrity sha512-/xL2AbW/XWHNu1gnIrO8UitBGoFthcsDgU9VLK1/dpsoxbaD5LscHozKze05R6WLsBvLhqv78dAPozMFQBYLbQ==
integrity sha512-/xL2AbW/XWHNu1gnIrO8UitBGoFthcsDgU9VLK1/dpsoxbaD5LscHozKze05R6WLsBvLhqv78dAPozMFQBYLbQ==
...
@@ -7707,7 +7707,7 @@ gulp-mocha@^6.0.0:
...
@@ -7707,7 +7707,7 @@ gulp-mocha@^6.0.0:
supports-color "^5.4.0"
supports-color "^5.4.0"
through2 "^2.0.3"
through2 "^2.0.3"
gzip-size@^5.0.0:
gzip-size@
5.1.1, gzip-size@
^5.0.0:
version "5.1.1"
version "5.1.1"
resolved "https://registry.yarnpkg.com/gzip-size/-/gzip-size-5.1.1.tgz#cb9bee692f87c0612b232840a873904e4c135274"
resolved "https://registry.yarnpkg.com/gzip-size/-/gzip-size-5.1.1.tgz#cb9bee692f87c0612b232840a873904e4c135274"
integrity sha512-FNHi6mmoHvs1mxZAds4PpdCS6QG8B4C1krxJsMutgxl5t3+GlRTzzI3NEkifXx2pVsOvJdOGSmIgDhQ55FwdPA==
integrity sha512-FNHi6mmoHvs1mxZAds4PpdCS6QG8B4C1krxJsMutgxl5t3+GlRTzzI3NEkifXx2pVsOvJdOGSmIgDhQ55FwdPA==
...
...
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