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
e76529a4
Commit
e76529a4
authored
May 28, 2019
by
Lukáš Huvar
Committed by
Tim Neutkens
May 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bundle only server code for API routes (#7443)
parent
eee19788
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
18 deletions
+33
-18
on-demand-entry-handler.js
packages/next/server/on-demand-entry-handler.js
+33
-18
No files found.
packages/next/server/on-demand-entry-handler.js
View file @
e76529a4
...
@@ -52,6 +52,9 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, {
...
@@ -52,6 +52,9 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, {
invalidator
.
startBuilding
()
invalidator
.
startBuilding
()
const
allEntries
=
Object
.
keys
(
entries
).
map
(
async
(
page
)
=>
{
const
allEntries
=
Object
.
keys
(
entries
).
map
(
async
(
page
)
=>
{
if
(
compiler
.
name
===
'client'
&&
page
.
startsWith
(
'/api'
))
{
return
}
const
{
name
,
absolutePagePath
}
=
entries
[
page
]
const
{
name
,
absolutePagePath
}
=
entries
[
page
]
const
pageExists
=
await
isWriteable
(
absolutePagePath
)
const
pageExists
=
await
isWriteable
(
absolutePagePath
)
if
(
!
pageExists
)
{
if
(
!
pageExists
)
{
...
@@ -69,31 +72,30 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, {
...
@@ -69,31 +72,30 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, {
})
})
}
}
multiCompiler
.
hooks
.
done
.
tap
(
'NextJsOnDemandEntries'
,
(
multiStats
)
=>
{
function
findHardFailedPages
(
errors
)
{
const
clientStats
=
multiStats
.
stats
[
0
]
return
errors
.
filter
(
e
=>
{
const
{
compilation
}
=
clientStats
// Make sure to only pick errors which marked with missing modules
const
hardFailedPages
=
compilation
.
errors
const
hasNoModuleFoundError
=
/ENOENT/
.
test
(
e
.
message
)
||
/Module not found/
.
test
(
e
.
message
)
.
filter
(
e
=>
{
if
(
!
hasNoModuleFoundError
)
return
false
// Make sure to only pick errors which marked with missing modules
const
hasNoModuleFoundError
=
/ENOENT/
.
test
(
e
.
message
)
||
/Module not found/
.
test
(
e
.
message
)
// The page itself is missing. So this is a failed page.
if
(
!
hasNoModuleFoundError
)
return
false
if
(
IS_BUNDLED_PAGE_REGEX
.
test
(
e
.
module
.
name
))
return
true
// The page itself is missing. So this is a failed page.
// No dependencies means this is a top level page.
if
(
IS_BUNDLED_PAGE_REGEX
.
test
(
e
.
module
.
name
))
return
true
// So this is a failed page.
return
e
.
module
.
dependencies
.
length
===
0
// No dependencies means this is a top level page.
})
// So this is a failed page.
return
e
.
module
.
dependencies
.
length
===
0
})
.
map
(
e
=>
e
.
module
.
chunks
)
.
map
(
e
=>
e
.
module
.
chunks
)
.
reduce
((
a
,
b
)
=>
[...
a
,
...
b
],
[])
.
reduce
((
a
,
b
)
=>
[...
a
,
...
b
],
[])
.
map
(
c
=>
{
.
map
(
c
=>
{
const
pageName
=
ROUTE_NAME_REGEX
.
exec
(
c
.
name
)[
1
]
const
pageName
=
ROUTE_NAME_REGEX
.
exec
(
c
.
name
)[
1
]
return
normalizePage
(
`/
${
pageName
}
`
)
return
normalizePage
(
`/
${
pageName
}
`
)
})
})
}
// compilation.entrypoints is a Map object, so iterating over it 0 is the key and 1 is the value
function
getPagePathsFromEntrypoints
(
entrypoints
)
{
for
(
const
[,
entrypoint
]
of
compilation
.
entrypoints
.
entries
())
{
const
pagePaths
=
[]
for
(
const
[,
entrypoint
]
of
entrypoints
.
entries
())
{
const
result
=
ROUTE_NAME_REGEX
.
exec
(
entrypoint
.
name
)
const
result
=
ROUTE_NAME_REGEX
.
exec
(
entrypoint
.
name
)
if
(
!
result
)
{
if
(
!
result
)
{
continue
continue
...
@@ -105,6 +107,19 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, {
...
@@ -105,6 +107,19 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, {
continue
continue
}
}
pagePaths
.
push
(
pagePath
)
}
return
pagePaths
}
multiCompiler
.
hooks
.
done
.
tap
(
'NextJsOnDemandEntries'
,
(
multiStats
)
=>
{
const
[
clientStats
,
serverStats
]
=
multiStats
.
stats
const
hardFailedPages
=
[...
new
Set
([...
findHardFailedPages
(
clientStats
.
compilation
.
errors
),
...
findHardFailedPages
(
serverStats
.
compilation
.
errors
)])]
const
pagePaths
=
new
Set
([...
getPagePathsFromEntrypoints
(
clientStats
.
compilation
.
entrypoints
),
...(
getPagePathsFromEntrypoints
(
serverStats
.
compilation
.
entrypoints
))])
// compilation.entrypoints is a Map object, so iterating over it 0 is the key and 1 is the value
for
(
const
pagePath
of
pagePaths
)
{
const
page
=
normalizePage
(
'/'
+
pagePath
)
const
page
=
normalizePage
(
'/'
+
pagePath
)
const
entry
=
entries
[
page
]
const
entry
=
entries
[
page
]
...
...
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