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
b8e8228e
Commit
b8e8228e
authored
Oct 08, 2018
by
Tim Neutkens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compile build-manifest per-page
parent
77a138cc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
42 deletions
+41
-42
constants.js
packages/next-server/lib/constants.js
+0
-1
render.js
packages/next-server/server/render.js
+3
-20
build-manifest-plugin.js
packages/next/build/webpack/plugins/build-manifest-plugin.js
+36
-17
rendering.js
test/integration/basic/test/rendering.js
+1
-2
index.test.js
test/integration/production/test/index.test.js
+1
-2
No files found.
packages/next-server/lib/constants.js
View file @
b8e8228e
...
...
@@ -3,7 +3,6 @@ export const PHASE_PRODUCTION_BUILD = 'phase-production-build'
export
const
PHASE_PRODUCTION_SERVER
=
'phase-production-server'
export
const
PHASE_DEVELOPMENT_SERVER
=
'phase-development-server'
export
const
PAGES_MANIFEST
=
'pages-manifest.json'
export
const
BUILD_MANIFEST
=
'build-manifest.json'
export
const
SERVER_DIRECTORY
=
'server'
export
const
CONFIG_FILE
=
'next.config.js'
export
const
BUILD_ID_FILE
=
'BUILD_ID'
...
...
packages/next-server/server/render.js
View file @
b8e8228e
...
...
@@ -13,7 +13,7 @@ import Loadable from '../lib/loadable'
import
LoadableCapture
from
'../lib/loadable-capture'
import
{
promisify
}
from
'util'
import
fs
from
'fs'
import
{
BUILD_MANIFEST
,
SERVER_DIRECTORY
,
CLIENT_STATIC_FILES_PATH
}
from
'next-server/constants'
import
{
SERVER_DIRECTORY
,
CLIENT_STATIC_FILES_PATH
}
from
'next-server/constants'
const
access
=
promisify
(
fs
.
access
)
...
...
@@ -49,17 +49,6 @@ export function renderErrorToHTML (err, req, res, pathname, query, opts = {}) {
return
doRender
(
req
,
res
,
pathname
,
query
,
{
...
opts
,
err
,
page
:
'/_error'
})
}
function
getPageFiles
(
buildManifest
,
normalizedPagePath
)
{
const
files
=
buildManifest
.
pages
[
normalizedPagePath
]
if
(
!
files
)
{
console
.
warn
(
`Could not find files for
${
normalizedPagePath
}
in .next/build-manifest.json`
)
return
[]
}
return
files
}
async
function
doRender
(
req
,
res
,
pathname
,
query
,
{
err
,
page
,
...
...
@@ -107,7 +96,7 @@ async function doRender (req, res, pathname, query, {
Component
=
Component
.
default
||
Component
const
reactLoadableManifest
=
require
(
pagePath
+
'-loadable.json'
)
const
buildManifest
=
require
(
join
(
distDir
,
BUILD_MANIFEST
)
)
const
buildManifest
=
require
(
pagePath
+
'-assets.json'
)
if
(
typeof
Component
!==
'function'
)
{
throw
new
Error
(
`The default export is not a React Component in page: "
${
page
}
"`
)
...
...
@@ -117,13 +106,7 @@ async function doRender (req, res, pathname, query, {
const
ctx
=
{
err
,
req
,
res
,
pathname
,
query
,
asPath
}
const
router
=
new
Router
(
pathname
,
query
,
asPath
)
const
props
=
await
loadGetInitialProps
(
App
,
{
Component
,
router
,
ctx
})
const
files
=
[
...
new
Set
([
...
getPageFiles
(
buildManifest
,
normalizedPagePath
),
...
getPageFiles
(
buildManifest
,
'/_app'
),
...
getPageFiles
(
buildManifest
,
'/_error'
)
])
]
const
files
=
buildManifest
.
assets
// the response might be finshed on the getinitialprops call
if
(
isResSent
(
res
))
return
...
...
packages/next/build/webpack/plugins/build-manifest-plugin.js
View file @
b8e8228e
// @flow
import
{
RawSource
}
from
'webpack-sources
'
import
{
BUILD_MANIFEST
,
ROUTE_NAME_REGEX
,
IS_BUNDLED_PAGE_REGEX
,
CLIENT_STATIC_FILES_RUNTIME_MAIN
}
from
'next-server/constants'
import
path
from
'path
'
import
{
ROUTE_NAME_REGEX
,
IS_BUNDLED_PAGE_REGEX
,
CLIENT_STATIC_FILES_RUNTIME_MAIN
}
from
'next-server/constants'
// This plugin creates a build-manifest.json for all assets that are being output
// It has a mapping of "entry" filename to real filename. Because the real filename can be hashed in production
export
default
class
BuildManifestPlugin
{
apply
(
compiler
:
any
)
{
compiler
.
hooks
.
emit
.
tap
Async
(
'NextJsBuildManifest'
,
(
compilation
,
callback
)
=>
{
compiler
.
hooks
.
emit
.
tap
Promise
(
'NextJsBuildManifest'
,
async
(
compilation
,
callback
)
=>
{
const
{
chunks
}
=
compilation
const
assetMap
=
{
devFiles
:
[],
pages
:
{}
}
const
assetMap
=
{}
const
mainJsChunk
=
chunks
.
find
((
c
)
=>
c
.
name
===
CLIENT_STATIC_FILES_RUNTIME_MAIN
)
const
mainJsFiles
=
mainJsChunk
&&
mainJsChunk
.
files
.
length
>
0
?
mainJsChunk
.
files
.
filter
((
file
)
=>
/
\.
js$/
.
test
(
file
))
:
[]
for
(
const
filePath
of
Object
.
keys
(
compilation
.
assets
))
{
const
path
=
filePath
.
replace
(
/
\\
/g
,
'/'
)
if
(
/^static
\/
development
\/
dll
\/
/
.
test
(
path
))
{
assetMap
.
devFiles
.
push
(
path
)
}
}
// compilation.entrypoints is a Map object, so iterating over it 0 is the key and 1 is the value
for
(
const
[,
entrypoint
]
of
compilation
.
entrypoints
.
entries
())
{
const
result
=
ROUTE_NAME_REGEX
.
exec
(
entrypoint
.
name
)
...
...
@@ -59,15 +52,41 @@ export default class BuildManifestPlugin {
}
}
assetMap
.
pages
[
`/
${
pagePath
.
replace
(
/
\\
/g
,
'/'
)}
`
]
=
[...
filesForEntry
,
...
mainJsFiles
]
assetMap
[
pagePath
.
replace
(
/
\\
/g
,
'/'
)
]
=
[...
filesForEntry
,
...
mainJsFiles
]
}
if
(
typeof
assetMap
.
pages
[
'/index'
]
!==
'undefined'
)
{
assetMap
.
pages
[
'/'
]
=
assetMap
.
pages
[
'/index'
]
}
for
(
const
[,
entrypoint
]
of
compilation
.
entrypoints
.
entries
())
{
const
manifestFile
=
path
.
join
(
'server'
,
entrypoint
.
name
.
replace
(
/
\.
js$/
,
'-assets.json'
))
const
result
=
ROUTE_NAME_REGEX
.
exec
(
entrypoint
.
name
)
if
(
!
result
)
{
continue
}
compilation
.
assets
[
BUILD_MANIFEST
]
=
new
RawSource
(
JSON
.
stringify
(
assetMap
,
null
,
2
))
callback
()
const
pagePath
=
result
[
1
]
if
(
!
pagePath
)
{
continue
}
const
assets
=
[
...
new
Set
([
...(
assetMap
[
'/_app'
]
||
[]),
...(
assetMap
[
'/_error'
]
||
[]),
...(
assetMap
[
pagePath
.
replace
(
/
\\
/g
,
'/'
)]
||
[])
])
]
const
json
=
JSON
.
stringify
({
assets
})
compilation
.
assets
[
manifestFile
]
=
{
source
()
{
return
json
},
size
()
{
return
json
.
length
}
}
}
})
}
}
test/integration/basic/test/rendering.js
View file @
b8e8228e
/* global describe, test, it, expect */
import
cheerio
from
'cheerio'
import
{
BUILD_MANIFEST
}
from
'next-server/constants'
import
{
join
}
from
'path'
export
default
function
({
app
},
suiteName
,
render
,
fetch
,
appPort
)
{
...
...
@@ -172,7 +171,7 @@ export default function ({ app }, suiteName, render, fetch, appPort) {
// build dynamic page
await
fetch
(
'/dynamic/ssr'
)
const
buildManifest
=
require
(
join
(
'../.next'
,
BUILD_MANIFEST
))
const
buildManifest
=
require
(
join
(
'../.next'
,
'server'
,
'static'
,
buildId
,
'pages'
,
'dynamic'
,
'ssr-assets.json'
))
const
reactLoadableManifest
=
require
(
join
(
'../.next'
,
'server'
,
'static'
,
buildId
,
'pages'
,
'dynamic'
,
'ssr-loadable.json'
))
const
resources
=
[]
...
...
test/integration/production/test/index.test.js
View file @
b8e8228e
...
...
@@ -16,7 +16,6 @@ import fetch from 'node-fetch'
import
dynamicImportTests
from
'./dynamic'
import
processEnv
from
'./process-env'
import
security
from
'./security'
import
{
BUILD_MANIFEST
}
from
'next-server/constants'
const
appDir
=
join
(
__dirname
,
'../'
)
let
appPort
...
...
@@ -78,7 +77,7 @@ describe('Production Usage', () => {
it
(
'should set Cache-Control header'
,
async
()
=>
{
const
buildId
=
readFileSync
(
join
(
__dirname
,
'../.next/BUILD_ID'
),
'utf8'
)
const
buildManifest
=
require
(
join
(
'../.next'
,
BUILD_MANIFEST
))
const
buildManifest
=
require
(
join
(
'../.next'
,
'server'
,
'static'
,
buildId
,
'pages'
,
'dynamic'
,
'ssr-assets.json'
))
const
reactLoadableManifest
=
require
(
join
(
'../.next'
,
'server'
,
'static'
,
buildId
,
'pages'
,
'dynamic'
,
'ssr-loadable.json'
))
const
url
=
`http://localhost:
${
appPort
}
/_next/`
...
...
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