Skip to content

Commit

Permalink
Add webpack-bundle-analyzer example (#1110)
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens authored and arunoda committed Feb 14, 2017
1 parent 9d529ea commit 2f7cc9c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/with-webpack-bundle-analyzer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

# Webpack Bundle Analyzer example

## How to use

Download the example [or clone the repo](https://github.com/zeit/next.js):

```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-webpack-bundle-analyzer
cd hello-world
```

Install it and run:

```bash
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

This example shows how to analyze the output bundles using [webpack-bundle-analyzer](https://github.com/th0r/webpack-bundle-analyzer#as-plugin)
17 changes: 17 additions & 0 deletions examples/with-webpack-bundle-analyzer/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer')
module.exports = {
webpack: (config, { dev }) => {
// Perform customizations to config
config.plugins.push(
new BundleAnalyzerPlugin({
// For all options see https://github.com/th0r/webpack-bundle-analyzer#as-plugin
analyzerMode: 'server',
analyzerHost: '127.0.0.1',
analyzerPort: 8888,
openAnalyzer: false
})
)
// Important: return the modified config
return config
}
}
17 changes: 17 additions & 0 deletions examples/with-webpack-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "hello-world",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "beta",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"webpack-bundle-analyzer": "^2.3.0"
},
"author": "",
"license": "ISC"
}
3 changes: 3 additions & 0 deletions examples/with-webpack-bundle-analyzer/pages/about.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default () => (
<div>About us</div>
)
4 changes: 4 additions & 0 deletions examples/with-webpack-bundle-analyzer/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Link from 'next/link'
export default () => (
<div>Hello World. <Link href='/about'><a>About</a></Link></div>
)

0 comments on commit 2f7cc9c

Please sign in to comment.