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
23c2f02f
Commit
23c2f02f
authored
Jun 28, 2017
by
Arunoda Susiripala
Committed by
GitHub
Jun 28, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it easy and meaningful to analyze the bundle. (#2393)
parent
12e8b126
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
30 deletions
+59
-30
README.md
examples/with-webpack-bundle-analyzer/README.md
+6
-9
next.config.js
examples/with-webpack-bundle-analyzer/next.config.js
+12
-13
package.json
examples/with-webpack-bundle-analyzer/package.json
+6
-4
contact.js
examples/with-webpack-bundle-analyzer/pages/contact.js
+5
-0
index.js
examples/with-webpack-bundle-analyzer/pages/index.js
+28
-3
combine-assets-plugin.js
server/build/plugins/combine-assets-plugin.js
+2
-1
No files found.
examples/with-webpack-bundle-analyzer/README.md
View file @
23c2f02f
...
@@ -11,21 +11,18 @@ curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2
...
@@ -11,21 +11,18 @@ curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2
cd
with-webpack-bundle-analyzer
cd
with-webpack-bundle-analyzer
```
```
Install it
and run:
Install it
```
bash
```
bash
npm
install
npm
install
npm run dev
```
Deploy it to the cloud with
[
now
](
https://zeit.co/now
)
(
[download](https://zeit.co/download
)
)
```
bash
now
```
```
## The idea behind the example
## The idea behind the example
This example shows how to analyze the output bundles using
[
webpack-bundle-analyzer
](
https://github.com/th0r/webpack-bundle-analyzer#as-plugin
)
This example shows how to analyze the output bundles using
[
webpack-bundle-analyzer
](
https://github.com/th0r/webpack-bundle-analyzer#as-plugin
)
To view the stats use
`npm run bundle:view`
To analyze your webpack output, invoke the following command:
```
bash
npm run analyze
```
examples/with-webpack-bundle-analyzer/next.config.js
View file @
23c2f02f
const
{
BundleAnalyzerPlugin
}
=
require
(
'webpack-bundle-analyzer'
)
const
{
BundleAnalyzerPlugin
}
=
require
(
'webpack-bundle-analyzer'
)
const
{
ANALYZE
}
=
process
.
env
module
.
exports
=
{
module
.
exports
=
{
webpack
:
(
config
,
{
dev
})
=>
{
webpack
:
function
(
config
)
{
// Perform customizations to config
if
(
ANALYZE
)
{
config
.
plugins
.
push
(
config
.
plugins
.
push
(
new
BundleAnalyzerPlugin
({
new
BundleAnalyzerPlugin
({
analyzerMode
:
'server'
,
analyzerMode
:
'disabled'
,
analyzerPort
:
8888
,
// For all options see https://github.com/th0r/webpack-bundle-analyzer#as-plugin
openAnalyzer
:
true
generateStatsFile
:
true
,
}))
// Will be available at `.next/stats.json`
}
statsFilename
:
'stats.json'
})
)
// Important: return the modified config
return
config
return
config
}
}
}
}
examples/with-webpack-bundle-analyzer/package.json
View file @
23c2f02f
...
@@ -5,13 +5,15 @@
...
@@ -5,13 +5,15 @@
"dev"
:
"next"
,
"dev"
:
"next"
,
"build"
:
"next build"
,
"build"
:
"next build"
,
"start"
:
"next start"
,
"start"
:
"next start"
,
"
bundle:view"
:
"webpack-bundle-analyzer .next/stats.json
"
"
analyze"
:
"cross-env ANALYZE=1 next build
"
},
},
"dependencies"
:
{
"dependencies"
:
{
"next"
:
"latest"
,
"next"
:
"latest"
,
"react"
:
"^15.4.2"
,
"cross-env"
:
"^5.0.1"
,
"react-dom"
:
"^15.4.2"
,
"faker"
:
"^4.1.0"
,
"webpack-bundle-analyzer"
:
"^2.3.0"
"react"
:
"^15.6.1"
,
"react-dom"
:
"^15.6.1"
,
"webpack-bundle-analyzer"
:
"^2.8.2"
},
},
"author"
:
""
,
"author"
:
""
,
"license"
:
"ISC"
"license"
:
"ISC"
...
...
examples/with-webpack-bundle-analyzer/pages/contact.js
0 → 100644
View file @
23c2f02f
export
default
()
=>
(
<
div
>
This
is
the
contact
page
.
<
/div
>
)
examples/with-webpack-bundle-analyzer/pages/index.js
View file @
23c2f02f
import
React
from
'react'
import
Link
from
'next/link'
import
Link
from
'next/link'
export
default
()
=>
(
<
div
>
Hello
World
.
<
Link
href
=
'/about'
><
a
>
About
<
/a></
Link
><
/div
>
export
default
class
Index
extends
React
.
Component
{
)
static
getInitialProps
({
req
})
{
if
(
req
)
{
// Runs only in the server
const
faker
=
require
(
'faker'
)
const
name
=
faker
.
name
.
findName
()
return
{
name
}
}
// Runs only in the client
return
{
name
:
'Arunoda'
}
}
render
()
{
const
{
name
}
=
this
.
props
return
(
<
div
>
<
h1
>
Home
Page
<
/h1
>
<
p
>
Welcome
,
{
name
}
<
/p
>
<
div
>
<
Link
href
=
'/about'
><
a
>
About
Page
<
/a></
Link
>
<
/div
>
<
/div
>
)
}
}
server/build/plugins/combine-assets-plugin.js
View file @
23c2f02f
...
@@ -15,7 +15,8 @@ export default class CombineAssetsPlugin {
...
@@ -15,7 +15,8 @@ export default class CombineAssetsPlugin {
if
(
!
asset
)
return
if
(
!
asset
)
return
newSource
+=
`
${
asset
.
source
()}
\n`
newSource
+=
`
${
asset
.
source
()}
\n`
delete
compilation
.
assets
[
name
]
// We keep existing assets since that helps when analyzing the bundle
})
})
compilation
.
assets
[
this
.
output
]
=
{
compilation
.
assets
[
this
.
output
]
=
{
...
...
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