Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoCo_Code_Op2
next.js
提交
a32af59e
N
next.js
项目概览
CoCo_Code_Op2
/
next.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
next.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a32af59e
编写于
12月 14, 2019
作者:
J
JJ Kasper
提交者:
Joe Haddad
12月 14, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix Shared Sizes Missing Commons (#9752)
* Fix shared sizes missing commons * Add tests
上级
eee4efd0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
70 addition
and
6 deletion
+70
-6
packages/next/build/index.ts
packages/next/build/index.ts
+4
-1
packages/next/build/utils.ts
packages/next/build/utils.ts
+30
-5
test/integration/build-output/fixtures/with-amp/pages/amp.js
test/integration/build-output/fixtures/with-amp/pages/amp.js
+2
-0
test/integration/build-output/fixtures/with-amp/pages/hybrid.js
...ntegration/build-output/fixtures/with-amp/pages/hybrid.js
+2
-0
test/integration/build-output/fixtures/with-amp/pages/index.js
...integration/build-output/fixtures/with-amp/pages/index.js
+3
-0
test/integration/build-output/test/index.test.js
test/integration/build-output/test/index.test.js
+29
-0
未找到文件。
packages/next/build/index.ts
浏览文件 @
a32af59e
...
...
@@ -384,8 +384,9 @@ export default async function build(dir: string, conf = null): Promise<void> {
bundleRelative
)
let
isStatic
=
false
let
isSsg
=
false
let
isStatic
=
false
let
isHybridAmp
=
false
let
ssgPageRoutes
:
string
[]
|
null
=
null
pagesManifest
[
page
]
=
bundleRelative
.
replace
(
/
\\
/g
,
'
/
'
)
...
...
@@ -430,6 +431,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
)
if
(
result
.
isHybridAmp
)
{
isHybridAmp
=
true
hybridAmpPages
.
add
(
page
)
}
...
...
@@ -456,6 +458,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
serverBundle
,
static
:
isStatic
,
isSsg
,
isHybridAmp
,
ssgPageRoutes
,
})
})
...
...
packages/next/build/utils.ts
浏览文件 @
a32af59e
...
...
@@ -32,6 +32,7 @@ export function collectPages(
export
interface
PageInfo
{
isAmp
?:
boolean
isHybridAmp
?:
boolean
size
:
number
static
:
boolean
isSsg
:
boolean
...
...
@@ -135,7 +136,12 @@ export async function printTreeView(
}
})
const
sharedData
=
await
getSharedSizes
(
distPath
,
buildManifest
,
isModern
)
const
sharedData
=
await
getSharedSizes
(
distPath
,
buildManifest
,
isModern
,
pageInfos
)
messages
.
push
([
'
+ shared by all
'
,
getPrettySize
(
sharedData
.
total
)])
Object
.
keys
(
sharedData
.
files
)
...
...
@@ -255,15 +261,18 @@ let cachedBuildManifest: BuildManifestShape | undefined
let
lastCompute
:
ComputeManifestShape
|
undefined
let
lastComputeModern
:
boolean
|
undefined
let
lastComputePageInfo
:
boolean
|
undefined
async
function
computeFromManifest
(
manifest
:
BuildManifestShape
,
distPath
:
string
,
isModern
:
boolean
isModern
:
boolean
,
pageInfos
?:
Map
<
string
,
PageInfo
>
):
Promise
<
ComputeManifestShape
>
{
if
(
Object
.
is
(
cachedBuildManifest
,
manifest
)
&&
lastComputeModern
===
isModern
lastComputeModern
===
isModern
&&
lastComputePageInfo
===
!!
pageInfos
)
{
return
lastCompute
!
}
...
...
@@ -275,6 +284,15 @@ async function computeFromManifest(
return
}
if
(
pageInfos
)
{
const
cleanKey
=
key
.
replace
(
/
\/
index$/
,
''
)
||
'
/
'
const
pageInfo
=
pageInfos
.
get
(
cleanKey
)
// don't include AMP pages since they don't rely on shared bundles
if
(
pageInfo
?.
isHybridAmp
||
pageInfo
?.
isAmp
)
{
return
}
}
++
expected
manifest
.
pages
[
key
].
forEach
(
file
=>
{
if
(
...
...
@@ -321,6 +339,7 @@ async function computeFromManifest(
cachedBuildManifest
=
manifest
lastComputeModern
=
isModern
lastComputePageInfo
=
!!
pageInfos
return
lastCompute
!
}
...
...
@@ -333,9 +352,15 @@ function difference<T>(main: T[], sub: T[]): T[] {
export
async
function
getSharedSizes
(
distPath
:
string
,
buildManifest
:
BuildManifestShape
,
isModern
:
boolean
isModern
:
boolean
,
pageInfos
:
Map
<
string
,
PageInfo
>
):
Promise
<
{
total
:
number
;
files
:
{
[
page
:
string
]:
number
}
}
>
{
const
data
=
await
computeFromManifest
(
buildManifest
,
distPath
,
isModern
)
const
data
=
await
computeFromManifest
(
buildManifest
,
distPath
,
isModern
,
pageInfos
)
return
{
total
:
data
.
sizeCommonFiles
,
files
:
data
.
sizeCommonFile
}
}
...
...
test/integration/build-output/fixtures/with-amp/pages/amp.js
0 → 100644
浏览文件 @
a32af59e
export
const
config
=
{
amp
:
true
}
export
default
()
=>
'
hi
'
test/integration/build-output/fixtures/with-amp/pages/hybrid.js
0 → 100644
浏览文件 @
a32af59e
export
const
config
=
{
amp
:
'
hybrid
'
}
export
default
()
=>
'
hi
'
test/integration/build-output/fixtures/with-amp/pages/index.js
0 → 100644
浏览文件 @
a32af59e
export
default
function
()
{
return
<
div
/>
}
test/integration/build-output/test/index.test.js
浏览文件 @
a32af59e
...
...
@@ -25,6 +25,7 @@ describe('Build Output', () => {
expect
(
stdout
).
toMatch
(
/
\/
[
]
*
\d{1,}
B/
)
expect
(
stdout
).
toMatch
(
/
\+
shared by all
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ runtime
\/
main
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ chunks
\/
commons
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
not
.
toContain
(
'
/_document
'
)
expect
(
stdout
).
not
.
toContain
(
'
/_app
'
)
...
...
@@ -50,6 +51,7 @@ describe('Build Output', () => {
expect
(
stdout
).
toMatch
(
/
\/
_app
[
]
*
\d{1,}
B/
)
expect
(
stdout
).
toMatch
(
/
\+
shared by all
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ runtime
\/
main
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ chunks
\/
commons
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
not
.
toContain
(
'
/_document
'
)
expect
(
stdout
).
not
.
toContain
(
'
/_error
'
)
...
...
@@ -59,6 +61,32 @@ describe('Build Output', () => {
})
})
describe
(
'
With AMP Output
'
,
()
=>
{
const
appDir
=
join
(
fixturesDir
,
'
with-amp
'
)
beforeAll
(
async
()
=>
{
await
remove
(
join
(
appDir
,
'
.next
'
))
})
it
(
'
should not include custom error
'
,
async
()
=>
{
const
{
stdout
}
=
await
nextBuild
(
appDir
,
[],
{
stdout
:
true
,
})
expect
(
stdout
).
toMatch
(
/
\/
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/
\/
amp .* AMP/
)
expect
(
stdout
).
toMatch
(
/
\/
hybrid
[
0-9.
]
* B/
)
expect
(
stdout
).
toMatch
(
/
\+
shared by all
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ runtime
\/
main
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ chunks
\/
commons
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
not
.
toContain
(
'
/_document
'
)
expect
(
stdout
).
not
.
toContain
(
'
/_error
'
)
expect
(
stdout
).
toContain
(
'
○ /
'
)
})
})
describe
(
'
Custom Error Output
'
,
()
=>
{
const
appDir
=
join
(
fixturesDir
,
'
with-error
'
)
...
...
@@ -75,6 +103,7 @@ describe('Build Output', () => {
expect
(
stdout
).
toMatch
(
/λ
\/
_error
[
]
*
\d{1,}
B/
)
expect
(
stdout
).
toMatch
(
/
\+
shared by all
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ runtime
\/
main
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
toMatch
(
/ chunks
\/
commons
\.
js
[
0-9.
]
* kB/
)
expect
(
stdout
).
not
.
toContain
(
'
/_document
'
)
expect
(
stdout
).
not
.
toContain
(
'
/_app
'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录