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
57ec121d
Unverified
Commit
57ec121d
authored
Jan 15, 2020
by
Joe Haddad
Committed by
GitHub
Jan 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename Build SPR to SSG (#10114)
parent
563f3c08
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
27 deletions
+26
-27
index.ts
packages/next/build/index.ts
+26
-27
No files found.
packages/next/build/index.ts
View file @
57ec121d
...
@@ -74,13 +74,13 @@ const mkdirp = promisify(mkdirpOrig)
...
@@ -74,13 +74,13 @@ const mkdirp = promisify(mkdirpOrig)
const
staticCheckWorker
=
require
.
resolve
(
'./utils'
)
const
staticCheckWorker
=
require
.
resolve
(
'./utils'
)
export
type
S
pr
Route
=
{
export
type
S
sg
Route
=
{
initialRevalidateSeconds
:
number
|
false
initialRevalidateSeconds
:
number
|
false
srcRoute
:
string
|
null
srcRoute
:
string
|
null
dataRoute
:
string
dataRoute
:
string
}
}
export
type
DynamicS
pr
Route
=
{
export
type
DynamicS
sg
Route
=
{
routeRegex
:
string
routeRegex
:
string
dataRoute
:
string
dataRoute
:
string
...
@@ -89,8 +89,8 @@ export type DynamicSprRoute = {
...
@@ -89,8 +89,8 @@ export type DynamicSprRoute = {
export
type
PrerenderManifest
=
{
export
type
PrerenderManifest
=
{
version
:
number
version
:
number
routes
:
{
[
route
:
string
]:
S
pr
Route
}
routes
:
{
[
route
:
string
]:
S
sg
Route
}
dynamicRoutes
:
{
[
route
:
string
]:
DynamicS
pr
Route
}
dynamicRoutes
:
{
[
route
:
string
]:
DynamicS
sg
Route
}
}
}
export
default
async
function
build
(
dir
:
string
,
conf
=
null
):
Promise
<
void
>
{
export
default
async
function
build
(
dir
:
string
,
conf
=
null
):
Promise
<
void
>
{
...
@@ -398,11 +398,11 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -398,11 +398,11 @@ export default async function build(dir: string, conf = null): Promise<void> {
)
)
const
buildManifestPath
=
path
.
join
(
distDir
,
BUILD_MANIFEST
)
const
buildManifestPath
=
path
.
join
(
distDir
,
BUILD_MANIFEST
)
const
s
pr
Pages
=
new
Set
<
string
>
()
const
s
sg
Pages
=
new
Set
<
string
>
()
const
staticPages
=
new
Set
<
string
>
()
const
staticPages
=
new
Set
<
string
>
()
const
invalidPages
=
new
Set
<
string
>
()
const
invalidPages
=
new
Set
<
string
>
()
const
hybridAmpPages
=
new
Set
<
string
>
()
const
hybridAmpPages
=
new
Set
<
string
>
()
const
additionalS
pr
Paths
=
new
Map
<
string
,
Array
<
string
>>
()
const
additionalS
sg
Paths
=
new
Map
<
string
,
Array
<
string
>>
()
const
pageInfos
=
new
Map
<
string
,
PageInfo
>
()
const
pageInfos
=
new
Map
<
string
,
PageInfo
>
()
const
pagesManifest
=
JSON
.
parse
(
await
fsReadFile
(
manifestPath
,
'utf8'
))
const
pagesManifest
=
JSON
.
parse
(
await
fsReadFile
(
manifestPath
,
'utf8'
))
const
buildManifest
=
JSON
.
parse
(
await
fsReadFile
(
buildManifestPath
,
'utf8'
))
const
buildManifest
=
JSON
.
parse
(
await
fsReadFile
(
buildManifestPath
,
'utf8'
))
...
@@ -491,11 +491,11 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -491,11 +491,11 @@ export default async function build(dir: string, conf = null): Promise<void> {
}
}
if
(
result
.
prerender
)
{
if
(
result
.
prerender
)
{
s
pr
Pages
.
add
(
page
)
s
sg
Pages
.
add
(
page
)
isSsg
=
true
isSsg
=
true
if
(
result
.
prerenderRoutes
)
{
if
(
result
.
prerenderRoutes
)
{
additionalS
pr
Paths
.
set
(
page
,
result
.
prerenderRoutes
)
additionalS
sg
Paths
.
set
(
page
,
result
.
prerenderRoutes
)
ssgPageRoutes
=
result
.
prerenderRoutes
ssgPageRoutes
=
result
.
prerenderRoutes
}
}
}
else
if
(
result
.
static
&&
customAppGetInitialProps
===
false
)
{
}
else
if
(
result
.
static
&&
customAppGetInitialProps
===
false
)
{
...
@@ -548,14 +548,13 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -548,14 +548,13 @@ export default async function build(dir: string, conf = null): Promise<void> {
await
writeBuildId
(
distDir
,
buildId
)
await
writeBuildId
(
distDir
,
buildId
)
const
finalPrerenderRoutes
:
{
[
route
:
string
]:
S
pr
Route
}
=
{}
const
finalPrerenderRoutes
:
{
[
route
:
string
]:
S
sg
Route
}
=
{}
const
tbdPrerenderRoutes
:
string
[]
=
[]
const
tbdPrerenderRoutes
:
string
[]
=
[]
if
(
staticPages
.
size
>
0
||
s
pr
Pages
.
size
>
0
)
{
if
(
staticPages
.
size
>
0
||
s
sg
Pages
.
size
>
0
)
{
const
combinedPages
=
[...
staticPages
,
...
s
pr
Pages
]
const
combinedPages
=
[...
staticPages
,
...
s
sg
Pages
]
const
exportApp
=
require
(
'../export'
).
default
const
exportApp
=
require
(
'../export'
).
default
const
exportOptions
=
{
const
exportOptions
=
{
sprPages
,
silent
:
true
,
silent
:
true
,
buildExport
:
true
,
buildExport
:
true
,
threads
:
config
.
experimental
.
cpus
,
threads
:
config
.
experimental
.
cpus
,
...
@@ -575,7 +574,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -575,7 +574,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
// to do so.
// to do so.
//
//
// Note: prerendering disables automatic static optimization.
// Note: prerendering disables automatic static optimization.
s
pr
Pages
.
forEach
(
page
=>
{
s
sg
Pages
.
forEach
(
page
=>
{
if
(
isDynamicRoute
(
page
))
{
if
(
isDynamicRoute
(
page
))
{
tbdPrerenderRoutes
.
push
(
page
)
tbdPrerenderRoutes
.
push
(
page
)
delete
defaultMap
[
page
]
delete
defaultMap
[
page
]
...
@@ -583,7 +582,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -583,7 +582,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
})
})
// Append the "well-known" routes we should prerender for, e.g. blog
// Append the "well-known" routes we should prerender for, e.g. blog
// post slugs.
// post slugs.
additionalS
pr
Paths
.
forEach
((
routes
,
page
)
=>
{
additionalS
sg
Paths
.
forEach
((
routes
,
page
)
=>
{
routes
.
forEach
(
route
=>
{
routes
.
forEach
(
route
=>
{
defaultMap
[
route
]
=
{
page
}
defaultMap
[
route
]
=
{
page
}
})
})
...
@@ -603,7 +602,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -603,7 +602,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
const
moveExportedPage
=
async
(
const
moveExportedPage
=
async
(
page
:
string
,
page
:
string
,
file
:
string
,
file
:
string
,
isS
pr
:
boolean
,
isS
sg
:
boolean
,
ext
:
'html'
|
'json'
ext
:
'html'
|
'json'
)
=>
{
)
=>
{
file
=
`
${
file
}
.
${
ext
}
`
file
=
`
${
file
}
.
${
ext
}
`
...
@@ -619,7 +618,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -619,7 +618,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
relativeDest
relativeDest
)
)
if
(
!
isS
pr
)
{
if
(
!
isS
sg
)
{
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
...
@@ -629,21 +628,21 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -629,21 +628,21 @@ export default async function build(dir: string, conf = null): Promise<void> {
}
}
for
(
const
page
of
combinedPages
)
{
for
(
const
page
of
combinedPages
)
{
const
isS
pr
=
spr
Pages
.
has
(
page
)
const
isS
sg
=
ssg
Pages
.
has
(
page
)
const
isDynamic
=
isDynamicRoute
(
page
)
const
isDynamic
=
isDynamicRoute
(
page
)
let
file
=
page
===
'/'
?
'/index'
:
page
let
file
=
page
===
'/'
?
'/index'
:
page
// The dynamic version of S
PR
pages are not prerendered. Below, we handle
// The dynamic version of S
SG
pages are not prerendered. Below, we handle
// the specific prerenders of these.
// the specific prerenders of these.
if
(
!
(
isS
pr
&&
isDynamic
))
{
if
(
!
(
isS
sg
&&
isDynamic
))
{
await
moveExportedPage
(
page
,
file
,
isS
pr
,
'html'
)
await
moveExportedPage
(
page
,
file
,
isS
sg
,
'html'
)
}
}
const
hasAmp
=
hybridAmpPages
.
has
(
page
)
const
hasAmp
=
hybridAmpPages
.
has
(
page
)
if
(
hasAmp
)
{
if
(
hasAmp
)
{
await
moveExportedPage
(
`
${
page
}
.amp`
,
`
${
file
}
.amp`
,
isS
pr
,
'html'
)
await
moveExportedPage
(
`
${
page
}
.amp`
,
`
${
file
}
.amp`
,
isS
sg
,
'html'
)
}
}
if
(
isS
pr
)
{
if
(
isS
sg
)
{
// For a non-dynamic S
PR
page, we must copy its data file from export.
// For a non-dynamic S
SG
page, we must copy its data file from export.
if
(
!
isDynamic
)
{
if
(
!
isDynamic
)
{
await
moveExportedPage
(
page
,
file
,
true
,
'json'
)
await
moveExportedPage
(
page
,
file
,
true
,
'json'
)
...
@@ -658,10 +657,10 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -658,10 +657,10 @@ export default async function build(dir: string, conf = null): Promise<void> {
),
),
}
}
}
else
{
}
else
{
// For a dynamic S
PR
page, we did not copy its html nor data exports.
// For a dynamic S
SG
page, we did not copy its html nor data exports.
// Instead, we must copy specific versions of this page as defined by
// Instead, we must copy specific versions of this page as defined by
// `unstable_getStaticPaths` (additionalS
pr
Paths).
// `unstable_getStaticPaths` (additionalS
sg
Paths).
const
extraRoutes
=
additionalS
pr
Paths
.
get
(
page
)
||
[]
const
extraRoutes
=
additionalS
sg
Paths
.
get
(
page
)
||
[]
for
(
const
route
of
extraRoutes
)
{
for
(
const
route
of
extraRoutes
)
{
await
moveExportedPage
(
route
,
route
,
true
,
'html'
)
await
moveExportedPage
(
route
,
route
,
true
,
'html'
)
await
moveExportedPage
(
route
,
route
,
true
,
'json'
)
await
moveExportedPage
(
route
,
route
,
true
,
'json'
)
...
@@ -699,7 +698,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -699,7 +698,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
})
})
)
)
if
(
s
pr
Pages
.
size
>
0
)
{
if
(
s
sg
Pages
.
size
>
0
)
{
const
finalDynamicRoutes
:
PrerenderManifest
[
'dynamicRoutes'
]
=
{}
const
finalDynamicRoutes
:
PrerenderManifest
[
'dynamicRoutes'
]
=
{}
tbdPrerenderRoutes
.
forEach
(
tbdRoute
=>
{
tbdPrerenderRoutes
.
forEach
(
tbdRoute
=>
{
const
dataRoute
=
path
.
posix
.
join
(
const
dataRoute
=
path
.
posix
.
join
(
...
...
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