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
bbf705f2
Unverified
Commit
bbf705f2
authored
Nov 04, 2019
by
Joe Haddad
Committed by
GitHub
Nov 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify Build Output (#9281)
* Simplify Build Output * Remove noop tests * Drop
⚡
* Remove bolding
parent
21f0db81
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
333 deletions
+37
-333
next.config.js
examples/with-patternfly/next.config.js
+16
-4
index.ts
packages/next/build/index.ts
+1
-4
utils.ts
packages/next/build/utils.ts
+13
-23
webpack-config.ts
packages/next/build/webpack-config.ts
+7
-13
chunk-graph-plugin.ts
packages/next/build/webpack/plugins/chunk-graph-plugin.ts
+0
-272
something.js
...egration/build-stats-output/react-site/pages/something.js
+0
-3
index.test.js
test/integration/build-stats-output/test/index.test.js
+0
-14
No files found.
examples/with-patternfly/next.config.js
View file @
bbf705f2
...
...
@@ -15,10 +15,22 @@ module.exports = withCSS(
// if they live under a 'fonts' or 'pficon' directory
include
:
[
path
.
resolve
(
__dirname
,
'node_modules/patternfly/dist/fonts'
),
path
.
resolve
(
__dirname
,
'node_modules/@patternfly/react-core/dist/styles/assets/fonts'
),
path
.
resolve
(
__dirname
,
'node_modules/@patternfly/react-core/dist/styles/assets/pficon'
),
path
.
resolve
(
__dirname
,
'node_modules/@patternfly/patternfly/assets/fonts'
),
path
.
resolve
(
__dirname
,
'node_modules/@patternfly/patternfly/assets/pficon'
)
path
.
resolve
(
__dirname
,
'node_modules/@patternfly/react-core/dist/styles/assets/fonts'
),
path
.
resolve
(
__dirname
,
'node_modules/@patternfly/react-core/dist/styles/assets/pficon'
),
path
.
resolve
(
__dirname
,
'node_modules/@patternfly/patternfly/assets/fonts'
),
path
.
resolve
(
__dirname
,
'node_modules/@patternfly/patternfly/assets/pficon'
)
],
use
:
{
loader
:
'file-loader'
,
...
...
packages/next/build/index.ts
View file @
bbf705f2
...
...
@@ -45,7 +45,6 @@ import {
printTreeView
,
}
from
'./utils'
import
getBaseWebpackConfig
from
'./webpack-config'
import
{
getPageChunks
}
from
'./webpack/plugins/chunk-graph-plugin'
import
{
writeBuildId
}
from
'./write-build-id'
const
fsAccess
=
promisify
(
fs
.
access
)
...
...
@@ -347,8 +346,6 @@ export default async function build(dir: string, conf = null): Promise<void> {
const
analysisBegin
=
process
.
hrtime
()
await
Promise
.
all
(
pageKeys
.
map
(
async
page
=>
{
const
chunks
=
getPageChunks
(
page
)
const
actualPage
=
page
===
'/'
?
'/index'
:
page
const
size
=
await
getPageSizeInKb
(
actualPage
,
...
...
@@ -434,7 +431,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
}
}
pageInfos
.
set
(
page
,
{
size
,
chunks
,
serverBundle
,
static
:
isStatic
})
pageInfos
.
set
(
page
,
{
size
,
serverBundle
,
static
:
isStatic
})
})
)
staticCheckWorkers
.
end
()
...
...
packages/next/build/utils.ts
View file @
bbf705f2
...
...
@@ -2,16 +2,15 @@ import chalk from 'chalk'
import
fs
from
'fs'
import
textTable
from
'next/dist/compiled/text-table'
import
path
from
'path'
import
{
isValidElementType
}
from
'react-is'
import
stripAnsi
from
'strip-ansi'
import
{
promisify
}
from
'util'
import
{
isValidElementType
}
from
'react-i
s'
import
{
SPR_GET_INITIAL_PROPS_CONFLICT
}
from
'../lib/constant
s'
import
prettyBytes
from
'../lib/pretty-bytes'
import
{
recursiveReadDir
}
from
'../lib/recursive-readdir'
import
{
getPageChunks
}
from
'./webpack/plugins/chunk-graph-plugin'
import
{
isDynamicRoute
}
from
'../next-server/lib/router/utils/is-dynamic'
import
{
getRouteMatcher
,
getRouteRegex
}
from
'../next-server/lib/router/utils'
import
{
SPR_GET_INITIAL_PROPS_CONFLICT
}
from
'../lib/constants
'
import
{
isDynamicRoute
}
from
'../next-server/lib/router/utils/is-dynamic
'
const
fsStatPromise
=
promisify
(
fs
.
stat
)
const
fileStats
:
{
[
k
:
string
]:
Promise
<
fs
.
Stats
>
}
=
{}
...
...
@@ -36,7 +35,6 @@ export function collectPages(
export
interface
PageInfo
{
isAmp
?:
boolean
size
:
number
chunks
?:
ReturnType
<
typeof
getPageChunks
>
static
?:
boolean
serverBundle
:
string
}
...
...
@@ -57,7 +55,7 @@ export function printTreeView(
}
const
messages
:
string
[][]
=
[
[
'Page'
,
'Size'
,
'Files'
,
'Packages'
].
map
(
entry
=>
chalk
.
underline
(
entry
)),
[
'Page'
,
'Size'
].
map
(
entry
=>
chalk
.
underline
(
entry
)),
]
list
...
...
@@ -79,22 +77,18 @@ export function printTreeView(
item
.
startsWith
(
'/_'
)
?
' '
:
pageInfo
&&
pageInfo
.
static
?
chalk
.
bold
(
'⚡'
)
?
'*'
:
serverless
?
'λ'
:
'σ'
}
${
item
}
`
,
...(
pageInfo
?
[
pageInfo
.
isAmp
?
chalk
.
cyan
(
'AMP'
)
:
pageInfo
.
size
>=
0
?
getPrettySize
(
pageInfo
.
size
)
:
''
,
pageInfo
.
chunks
?
pageInfo
.
chunks
.
internal
.
size
.
toString
()
:
''
,
pageInfo
.
chunks
?
pageInfo
.
chunks
.
external
.
size
.
toString
()
:
''
,
]
:
[
''
,
''
,
''
]),
pageInfo
?
pageInfo
.
isAmp
?
chalk
.
cyan
(
'AMP'
)
:
pageInfo
.
size
>=
0
?
getPrettySize
(
pageInfo
.
size
)
:
''
:
''
,
])
})
...
...
@@ -124,11 +118,7 @@ export function printTreeView(
'getInitialProps'
)}
)`
,
],
[
chalk
.
bold
(
'⚡'
),
'(Static File)'
,
'page was prerendered as static HTML'
,
],
[
'*'
,
'(Static File)'
,
'page was prerendered as static HTML'
],
],
{
align
:
[
'l'
,
'l'
,
'l'
],
...
...
packages/next/build/webpack-config.ts
View file @
bbf705f2
...
...
@@ -25,8 +25,14 @@ import {
}
from
'../next-server/lib/constants'
import
{
findPageFile
}
from
'../server/lib/find-page-file'
import
{
WebpackEntrypoints
}
from
'./entries'
import
{
collectPlugins
,
PluginMetaData
,
VALID_MIDDLEWARE
,
}
from
'./plugins/collect-plugins'
// @ts-ignore: JS file
import
{
pluginLoaderOptions
}
from
'./webpack/loaders/next-plugin-loader'
import
BuildManifestPlugin
from
'./webpack/plugins/build-manifest-plugin'
import
{
ChunkGraphPlugin
}
from
'./webpack/plugins/chunk-graph-plugin'
import
ChunkNamesPlugin
from
'./webpack/plugins/chunk-names-plugin'
import
{
CssMinimizerPlugin
}
from
'./webpack/plugins/css-minimizer-plugin'
import
{
importAutoDllPlugin
}
from
'./webpack/plugins/dll-import'
...
...
@@ -35,17 +41,10 @@ import NextEsmPlugin from './webpack/plugins/next-esm-plugin'
import
NextJsSsrImportPlugin
from
'./webpack/plugins/nextjs-ssr-import'
import
NextJsSSRModuleCachePlugin
from
'./webpack/plugins/nextjs-ssr-module-cache'
import
PagesManifestPlugin
from
'./webpack/plugins/pages-manifest-plugin'
// @ts-ignore: JS file
import
{
pluginLoaderOptions
}
from
'./webpack/loaders/next-plugin-loader'
import
{
ProfilingPlugin
}
from
'./webpack/plugins/profiling-plugin'
import
{
ReactLoadablePlugin
}
from
'./webpack/plugins/react-loadable-plugin'
import
{
ServerlessPlugin
}
from
'./webpack/plugins/serverless-plugin'
import
{
TerserPlugin
}
from
'./webpack/plugins/terser-webpack-plugin/src/index'
import
{
collectPlugins
,
VALID_MIDDLEWARE
,
PluginMetaData
,
}
from
'./plugins/collect-plugins'
type
ExcludesFalse
=
<
T
>
(
x
:
T
|
false
)
=>
x
is
T
...
...
@@ -829,11 +828,6 @@ export default async function getBaseWebpackConfig(
filename
:
REACT_LOADABLE_MANIFEST
,
}),
!
isServer
&&
new
DropClientPage
(),
new
ChunkGraphPlugin
(
buildId
,
{
dir
,
distDir
,
isServer
,
}),
// Moment.js is an extremely popular library that bundles large locale files
// by default due to how Webpack interprets its code. This is a practical
// solution that requires the user to opt into importing specific locales.
...
...
packages/next/build/webpack/plugins/chunk-graph-plugin.ts
deleted
100644 → 0
View file @
21f0db81
import
{
CLIENT_STATIC_FILES_RUNTIME_MAIN
}
from
'../../../next-server/lib/constants'
import
path
from
'path'
import
{
parse
}
from
'querystring'
import
{
Compiler
,
Plugin
}
from
'webpack'
type
StringDictionary
=
{
[
pageName
:
string
]:
string
[]
}
const
manifest
:
{
sharedFiles
:
string
[]
pages
:
StringDictionary
pageChunks
:
StringDictionary
chunks
:
StringDictionary
}
=
{
sharedFiles
:
[],
pages
:
{},
pageChunks
:
{},
chunks
:
{},
}
const
pageModules
:
StringDictionary
=
{}
export
function
getPageChunks
(
page
:
string
):
|
{
external
:
Set
<
String
>
internal
:
Set
<
String
>
}
|
undefined
{
if
(
!
manifest
.
pages
[
page
]
&&
!
pageModules
[
page
])
{
return
}
const
external
=
new
Set
<
string
>
()
// from node_modules
const
internal
=
new
Set
<
string
>
()
// from project
;[...(
manifest
.
pages
[
page
]
||
[]),
...(
pageModules
[
page
]
||
[])].
map
(
mod
=>
{
mod
=
mod
.
replace
(
/
\\
/g
,
'/'
)
if
(
mod
.
match
(
/
(
next-server|next
)\/
/
))
{
return
null
}
if
(
mod
.
includes
(
'node_modules/'
))
{
if
(
mod
.
match
(
/node_modules
\/(
@babel|core-js|styled-jsx|string-hash|object-assign|process|react|react-dom|scheduler|regenerator-runtime|webpack|node-libs-browser
)\/
/
)
)
{
return
null
}
mod
=
mod
.
split
(
'node_modules/'
)[
1
].
split
(
'/'
)[
0
]
if
(
external
.
has
(
mod
))
{
return
null
}
external
.
add
(
mod
)
return
mod
}
// don't include the page itself
if
(
mod
.
includes
(
`pages
${
page
===
'/'
?
'/index'
:
page
}
`
))
{
return
null
}
// is local e.g. ../components/Layout
if
(
internal
.
has
(
mod
))
{
return
null
}
internal
.
add
(
mod
)
return
mod
})
return
{
external
,
internal
,
}
}
function
getFiles
(
dir
:
string
,
modules
:
any
[]):
string
[]
{
if
(
!
(
modules
&&
modules
.
length
))
{
return
[]
}
function
getFileByIdentifier
(
id
:
string
)
{
if
(
id
.
startsWith
(
'external '
)
||
id
.
startsWith
(
'multi '
))
{
return
null
}
let
n
if
((
n
=
id
.
lastIndexOf
(
'!'
))
!==
-
1
)
{
id
=
id
.
substring
(
n
+
1
)
}
if
(
id
&&
!
path
.
isAbsolute
(
id
))
{
id
=
path
.
resolve
(
dir
,
id
)
}
return
id
}
return
modules
.
reduce
(
(
acc
:
any
[],
val
:
any
)
=>
val
.
modules
?
acc
.
concat
(
getFiles
(
dir
,
val
.
modules
))
:
(
acc
.
push
(
getFileByIdentifier
(
typeof
val
.
identifier
===
'function'
?
val
.
identifier
()
:
val
.
identifier
)
),
acc
),
[]
)
.
filter
(
Boolean
)
}
export
class
ChunkGraphPlugin
implements
Plugin
{
private
buildId
:
string
private
dir
:
string
private
distDir
:
string
private
isServer
:
boolean
constructor
(
buildId
:
string
,
{
dir
,
distDir
,
isServer
,
}:
{
dir
:
string
distDir
:
string
isServer
:
boolean
}
)
{
this
.
buildId
=
buildId
this
.
dir
=
dir
this
.
distDir
=
distDir
this
.
isServer
=
isServer
}
apply
(
compiler
:
Compiler
)
{
const
{
dir
}
=
this
compiler
.
hooks
.
emit
.
tap
(
'ChunkGraphPlugin'
,
compilation
=>
{
const
sharedFiles
=
[]
as
string
[]
const
sharedChunks
=
[]
as
string
[]
const
pages
:
StringDictionary
=
{}
const
pageChunks
:
StringDictionary
=
{}
compilation
.
chunks
.
forEach
(
chunk
=>
{
if
(
!
chunk
.
hasEntryModule
())
{
return
}
const
chunkModules
=
new
Map
<
any
,
any
>
()
const
queue
=
new
Set
<
any
>
(
chunk
.
groupsIterable
)
const
chunksProcessed
=
new
Set
<
any
>
()
const
involvedChunks
=
new
Set
<
string
>
()
for
(
const
chunkGroup
of
queue
)
{
for
(
const
chunk
of
chunkGroup
.
chunks
)
{
chunk
.
files
.
forEach
((
file
:
string
)
=>
involvedChunks
.
add
(
file
))
if
(
!
chunksProcessed
.
has
(
chunk
))
{
chunksProcessed
.
add
(
chunk
)
for
(
const
m
of
chunk
.
modulesIterable
)
{
chunkModules
.
set
(
m
.
id
,
m
)
}
}
}
for
(
const
child
of
chunkGroup
.
childrenIterable
)
{
queue
.
add
(
child
)
}
}
const
modules
=
[...
chunkModules
.
values
()]
const
nodeModules
:
string
[]
=
[]
const
files
=
getFiles
(
dir
,
modules
)
// we don't care about node_modules (yet) because we invalidate the
// entirety of flying shuttle on package changes
.
filter
(
val
=>
{
// store them for build tree stats though
const
isModule
=
val
.
includes
(
'node_modules'
)
if
(
isModule
)
nodeModules
.
push
(
val
)
return
!
isModule
})
// build artifacts shouldn't be considered, so we ensure all paths
// are outside of this directory
.
filter
(
val
=>
path
.
relative
(
this
.
distDir
,
val
).
startsWith
(
'..'
))
// convert from absolute path to be portable across operating systems
// and directories
.
map
(
f
=>
path
.
relative
(
dir
,
f
))
let
pageName
:
string
|
undefined
if
(
chunk
.
entryModule
&&
chunk
.
entryModule
.
loaders
)
{
const
entryLoader
=
chunk
.
entryModule
.
loaders
.
find
(
({
loader
,
options
,
}:
{
loader
?:
string
|
null
options
?:
string
|
null
})
=>
loader
&&
loader
.
match
(
/next-
(\w
+-
)
+loader/
)
&&
options
)
if
(
entryLoader
)
{
const
{
page
}
=
parse
(
entryLoader
.
options
)
if
(
typeof
page
===
'string'
&&
page
)
{
pageName
=
page
}
}
}
if
(
pageName
)
{
if
(
pageName
===
'/_app'
||
pageName
===
'/_error'
||
pageName
===
'/_document'
)
{
sharedFiles
.
push
(...
files
)
sharedChunks
.
push
(...
involvedChunks
)
}
else
{
pages
[
pageName
]
=
files
pageChunks
[
pageName
]
=
[...
involvedChunks
]
}
pageModules
[
pageName
]
=
nodeModules
}
else
{
if
(
chunk
.
name
===
CLIENT_STATIC_FILES_RUNTIME_MAIN
)
{
sharedFiles
.
push
(...
files
)
sharedChunks
.
push
(...
involvedChunks
)
}
else
{
manifest
.
chunks
[
chunk
.
name
]
=
[
...
new
Set
([...(
manifest
.
chunks
[
chunk
.
name
]
||
[]),
...
files
]),
].
sort
()
}
}
})
const
getLambdaChunk
=
(
name
:
string
)
=>
name
.
includes
(
this
.
buildId
)
?
name
.
replace
(
new
RegExp
(
`
${
this
.
buildId
}
[\\/\\\\]`
),
'client/'
)
.
replace
(
/
[
.
]
js$/
,
`.
${
this
.
buildId
}
.js`
)
:
name
manifest
.
sharedFiles
=
[
...
new
Set
([...(
manifest
.
sharedFiles
||
[]),
...
sharedFiles
]),
].
sort
()
for
(
const
page
in
pages
)
{
manifest
.
pages
[
page
]
=
[
...
new
Set
([...(
manifest
.
pages
[
page
]
||
[]),
...
pages
[
page
]]),
].
sort
()
// There's no chunks to save from serverless bundles
if
(
!
this
.
isServer
)
{
manifest
.
pageChunks
[
page
]
=
[
...
new
Set
([
...(
manifest
.
pageChunks
[
page
]
||
[]),
...
pageChunks
[
page
],
...
pageChunks
[
page
].
map
(
getLambdaChunk
),
...
sharedChunks
,
...
sharedChunks
.
map
(
getLambdaChunk
),
]),
].
sort
()
}
}
})
}
}
test/integration/build-stats-output/react-site/pages/something.js
deleted
100644 → 0
View file @
21f0db81
import
fetch
from
'isomorphic-unfetch'
console
.
log
(
fetch
)
export
default
()
=>
<
p
>
Hello
world
<
/p
>
test/integration/build-stats-output/test/index.test.js
deleted
100644 → 0
View file @
21f0db81
/* eslint-env jest */
/* global jasmine */
import
{
join
}
from
'path'
import
{
nextBuild
}
from
'next-test-utils'
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
1000
*
60
*
1
const
appDir
=
join
(
__dirname
,
'../react-site'
)
describe
(
'Build Stats Output'
,
()
=>
{
it
(
'Shows correct package count in output'
,
async
()
=>
{
const
{
stdout
}
=
await
nextBuild
(
appDir
,
undefined
,
{
stdout
:
true
})
expect
(
stdout
).
toMatch
(
/
\/
something .*
?
2/
)
})
})
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