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
674ba172
Unverified
Commit
674ba172
authored
Aug 23, 2019
by
JJ Kasper
Committed by
GitHub
Aug 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update prerender-manifest structure (#8497)
parent
483cd105
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
25 deletions
+28
-25
index.ts
packages/next/build/index.ts
+18
-17
index.test.js
test/integration/prerender/test/index.test.js
+10
-8
No files found.
packages/next/build/index.ts
View file @
674ba172
...
@@ -44,8 +44,8 @@ const mkdirp = promisify(mkdirpOrig)
...
@@ -44,8 +44,8 @@ const mkdirp = promisify(mkdirpOrig)
const
staticCheckWorker
=
require
.
resolve
(
'./static-checker'
)
const
staticCheckWorker
=
require
.
resolve
(
'./static-checker'
)
export
type
Prerender
Rout
e
=
{
export
type
Prerender
Fil
e
=
{
path
:
string
lambda
:
string
contentTypes
:
string
[]
contentTypes
:
string
[]
}
}
...
@@ -187,7 +187,6 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -187,7 +187,6 @@ export default async function build(dir: string, conf = null): Promise<void> {
console
.
log
(
chalk
.
green
(
'Compiled successfully.
\
n'
))
console
.
log
(
chalk
.
green
(
'Compiled successfully.
\
n'
))
}
}
const
distPath
=
path
.
join
(
dir
,
config
.
distDir
)
const
pageKeys
=
Object
.
keys
(
mappedPages
)
const
pageKeys
=
Object
.
keys
(
mappedPages
)
const
manifestPath
=
path
.
join
(
const
manifestPath
=
path
.
join
(
distDir
,
distDir
,
...
@@ -221,13 +220,13 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -221,13 +220,13 @@ export default async function build(dir: string, conf = null): Promise<void> {
const
chunks
=
getPageChunks
(
page
)
const
chunks
=
getPageChunks
(
page
)
const
actualPage
=
page
===
'/'
?
'/index'
:
page
const
actualPage
=
page
===
'/'
?
'/index'
:
page
const
size
=
await
getPageSizeInKb
(
actualPage
,
dist
Path
,
buildId
)
const
size
=
await
getPageSizeInKb
(
actualPage
,
dist
Dir
,
buildId
)
const
bundleRelative
=
path
.
join
(
const
bundleRelative
=
path
.
join
(
isLikeServerless
?
'pages'
:
`static/
${
buildId
}
/pages`
,
isLikeServerless
?
'pages'
:
`static/
${
buildId
}
/pages`
,
actualPage
+
'.js'
actualPage
+
'.js'
)
)
const
serverBundle
=
path
.
join
(
const
serverBundle
=
path
.
join
(
dist
Path
,
dist
Dir
,
isLikeServerless
?
SERVERLESS_DIRECTORY
:
SERVER_DIRECTORY
,
isLikeServerless
?
SERVERLESS_DIRECTORY
:
SERVER_DIRECTORY
,
bundleRelative
bundleRelative
)
)
...
@@ -247,7 +246,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -247,7 +246,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
isLikeServerless
isLikeServerless
?
serverBundle
?
serverBundle
:
path
.
join
(
:
path
.
join
(
dist
Path
,
dist
Dir
,
SERVER_DIRECTORY
,
SERVER_DIRECTORY
,
`/static/
${
buildId
}
/pages/_app.js`
`/static/
${
buildId
}
/pages/_app.js`
),
),
...
@@ -330,6 +329,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -330,6 +329,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
}
}
await
writeBuildId
(
distDir
,
buildId
)
await
writeBuildId
(
distDir
,
buildId
)
const
prerenderFiles
:
{
[
path
:
string
]:
PrerenderFile
}
=
{}
if
(
staticPages
.
size
>
0
||
sprPages
.
size
>
0
)
{
if
(
staticPages
.
size
>
0
||
sprPages
.
size
>
0
)
{
const
combinedPages
=
[...
staticPages
,
...
sprPages
]
const
combinedPages
=
[...
staticPages
,
...
sprPages
]
...
@@ -369,7 +369,17 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -369,7 +369,17 @@ export default async function build(dir: string, conf = null): Promise<void> {
relativeDest
relativeDest
)
)
if
(
!
isSpr
)
{
if
(
isSpr
)
{
const
projectRelativeDest
=
path
.
join
(
config
.
distDir
,
isLikeServerless
?
SERVERLESS_DIRECTORY
:
SERVER_DIRECTORY
,
relativeDest
)
prerenderFiles
[
projectRelativeDest
]
=
{
lambda
:
projectRelativeDest
.
replace
(
/
\.
html$/
,
'.js'
),
contentTypes
:
[
'application/json'
,
'text/html'
],
}
}
else
{
pagesManifest
[
page
]
=
relativeDest
pagesManifest
[
page
]
=
relativeDest
if
(
page
===
'/'
)
pagesManifest
[
'/index'
]
=
relativeDest
if
(
page
===
'/'
)
pagesManifest
[
'/index'
]
=
relativeDest
if
(
page
===
'/.amp'
)
pagesManifest
[
'/index.amp'
]
=
relativeDest
if
(
page
===
'/.amp'
)
pagesManifest
[
'/index.amp'
]
=
relativeDest
...
@@ -392,18 +402,9 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -392,18 +402,9 @@ export default async function build(dir: string, conf = null): Promise<void> {
}
}
if
(
sprPages
.
size
>
0
)
{
if
(
sprPages
.
size
>
0
)
{
const
prerenderRoutes
:
PrerenderRoute
[]
=
[]
sprPages
.
forEach
(
pg
=>
{
prerenderRoutes
.
push
({
path
:
pg
,
contentTypes
:
[
'application/json'
,
'text/html'
],
})
})
await
fsWriteFile
(
await
fsWriteFile
(
path
.
join
(
distDir
,
PRERENDER_MANIFEST
),
path
.
join
(
distDir
,
PRERENDER_MANIFEST
),
JSON
.
stringify
({
prerender
Rout
es
}),
JSON
.
stringify
({
prerender
Fil
es
}),
'utf8'
'utf8'
)
)
}
}
...
...
test/integration/prerender/test/index.test.js
View file @
674ba172
...
@@ -149,17 +149,19 @@ describe('SPR Prerender', () => {
...
@@ -149,17 +149,19 @@ describe('SPR Prerender', () => {
it
(
'outputs a prerender-manifest correctly'
,
async
()
=>
{
it
(
'outputs a prerender-manifest correctly'
,
async
()
=>
{
const
manifest
=
require
(
join
(
appDir
,
'.next'
,
'prerender-manifest.json'
))
const
manifest
=
require
(
join
(
appDir
,
'.next'
,
'prerender-manifest.json'
))
const
p
ages
=
manifest
.
prerenderRoutes
.
map
(
route
=>
route
.
path
)
const
p
rerenderablePaths
=
Object
.
keys
(
manifest
.
prerenderFiles
)
expect
(
JSON
.
stringify
(
p
age
s
.
sort
())).
toBe
(
expect
(
JSON
.
stringify
(
p
rerenderablePath
s
.
sort
())).
toBe
(
JSON
.
stringify
(
JSON
.
stringify
(
[
[
'/'
,
'/index.html'
,
'/another'
,
'/another.html'
,
'/something'
,
'/something.html'
,
'/blog/[post]'
,
'/blog/[post].html'
,
'/blog/[post]/[comment]'
'/blog/[post]/[comment].html'
].
sort
()
]
.
map
(
pg
=>
join
(
'.next/serverless/pages/'
,
pg
))
.
sort
()
)
)
)
)
})
})
...
...
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