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
2e32aa86
Unverified
Commit
2e32aa86
authored
Mar 12, 2019
by
Joe Haddad
Committed by
GitHub
Mar 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure correct key order (#6616)
* Ensure correct key order * Fix bug * Format this document while we're at it
parent
179d09e8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
49 deletions
+68
-49
build-manifest-plugin.js
packages/next/build/webpack/plugins/build-manifest-plugin.js
+68
-49
No files found.
packages/next/build/webpack/plugins/build-manifest-plugin.js
View file @
2e32aa86
import
{
RawSource
}
from
'webpack-sources'
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
{
BUILD_MANIFEST
,
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
// 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
// It has a mapping of "entry" filename to real filename. Because the real filename can be hashed in production
export
default
class
BuildManifestPlugin
{
export
default
class
BuildManifestPlugin
{
apply
(
compiler
)
{
apply
(
compiler
)
{
compiler
.
hooks
.
emit
.
tapAsync
(
'NextJsBuildManifest'
,
(
compilation
,
callback
)
=>
{
compiler
.
hooks
.
emit
.
tapAsync
(
const
{
chunks
}
=
compilation
'NextJsBuildManifest'
,
const
assetMap
=
{
devFiles
:
[],
pages
:
{}
}
(
compilation
,
callback
)
=>
{
const
{
chunks
}
=
compilation
const
assetMap
=
{
devFiles
:
[],
pages
:
{}
}
const
mainJsChunk
=
chunks
.
find
((
c
)
=>
c
.
name
===
CLIENT_STATIC_FILES_RUNTIME_MAIN
)
const
mainJsChunk
=
chunks
.
find
(
const
mainJsFiles
=
mainJsChunk
&&
mainJsChunk
.
files
.
length
>
0
?
mainJsChunk
.
files
.
filter
((
file
)
=>
/
\.
js$/
.
test
(
file
))
:
[]
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
))
{
for
(
const
filePath
of
Object
.
keys
(
compilation
.
assets
))
{
const
path
=
filePath
.
replace
(
/
\\
/g
,
'/'
)
const
path
=
filePath
.
replace
(
/
\\
/g
,
'/'
)
if
(
/^static
\/
development
\/
dll
\/
/
.
test
(
path
))
{
if
(
/^static
\/
development
\/
dll
\/
/
.
test
(
path
))
{
assetMap
.
devFiles
.
push
(
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
)
if
(
!
result
)
{
continue
}
}
const
pagePath
=
result
[
1
]
// 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
)
if
(
!
result
)
{
continue
}
if
(
!
pagePath
)
{
const
pagePath
=
result
[
1
]
continue
}
const
filesForEntry
=
[]
if
(
!
pagePath
)
{
for
(
const
chunk
of
entrypoint
.
chunks
)
{
// If there's no name or no files
if
(
!
chunk
.
name
||
!
chunk
.
files
)
{
continue
continue
}
}
for
(
const
file
of
chunk
.
files
)
{
const
filesForEntry
=
[]
if
(
/
\.
map$/
.
test
(
file
)
||
/
\.
hot-update
\.
js$/
.
test
(
file
))
{
for
(
const
chunk
of
entrypoint
.
chunks
)
{
// If there's no name or no files
if
(
!
chunk
.
name
||
!
chunk
.
files
)
{
continue
continue
}
}
// Only `.js` and `.css` files are added for now. In the future we can also handle other file types.
for
(
const
file
of
chunk
.
files
)
{
if
(
!
/
\.
js$/
.
test
(
file
)
&&
!
/
\.
cs
s$/
.
test
(
file
))
{
if
(
/
\.
map$/
.
test
(
file
)
||
/
\.
hot-update
\.
j
s$/
.
test
(
file
))
{
continue
continue
}
}
// The page bundles are manually added to _document.js as they need extra properties
// Only `.js` and `.css` files are added for now. In the future we can also handle other file types.
if
(
IS_BUNDLED_PAGE_REGEX
.
exec
(
file
))
{
if
(
!
/
\.
js$/
.
test
(
file
)
&&
!
/
\.
css$/
.
test
(
file
))
{
continue
continue
}
}
// The page bundles are manually added to _document.js as they need extra properties
if
(
IS_BUNDLED_PAGE_REGEX
.
exec
(
file
))
{
continue
}
filesForEntry
.
push
(
file
.
replace
(
/
\\
/g
,
'/'
))
filesForEntry
.
push
(
file
.
replace
(
/
\\
/g
,
'/'
))
}
}
}
}
assetMap
.
pages
[
`/
${
pagePath
.
replace
(
/
\\
/g
,
'/'
)}
`
]
=
[...
filesForEntry
,
...
mainJsFiles
]
assetMap
.
pages
[
`/
${
pagePath
.
replace
(
/
\\
/g
,
'/'
)}
`
]
=
[
}
...
filesForEntry
,
...
mainJsFiles
]
}
if
(
typeof
assetMap
.
pages
[
'/index'
]
!==
'undefined'
)
{
if
(
typeof
assetMap
.
pages
[
'/index'
]
!==
'undefined'
)
{
assetMap
.
pages
[
'/'
]
=
assetMap
.
pages
[
'/index'
]
assetMap
.
pages
[
'/'
]
=
assetMap
.
pages
[
'/index'
]
}
}
assetMap
.
pages
=
Object
.
keys
(
assetMap
.
pages
)
assetMap
.
pages
=
Object
.
keys
(
assetMap
.
pages
)
.
sort
()
.
sort
()
.
reduce
((
a
,
c
)
=>
Object
.
assign
(
a
,
{
[
c
]:
assetMap
.
pages
[
c
]
}),
{})
// eslint-disable-next-line
.
reduce
((
a
,
c
)
=>
((
a
[
c
]
=
assetMap
.
pages
[
c
]),
a
),
{})
compilation
.
assets
[
BUILD_MANIFEST
]
=
new
RawSource
(
JSON
.
stringify
(
assetMap
,
null
,
2
))
compilation
.
assets
[
BUILD_MANIFEST
]
=
new
RawSource
(
callback
()
JSON
.
stringify
(
assetMap
,
null
,
2
)
})
)
callback
()
}
)
}
}
}
}
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