Move next-bundle-analyzer to Next.js repo (#6445)

* Move next-bundle-analyzer to Next.js repo

* Remove options from bundle-analyzer
This commit is contained in:
JJ Kasper 2019-02-28 12:21:31 -06:00 committed by GitHub
parent cc2b7bc8fa
commit 42cff0a09c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 0 deletions

View file

@ -0,0 +1,20 @@
module.exports = ({ enabled = true } = {}) => (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack (config, options) {
if (enabled) {
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: options.isServer ? '../analyze/server.html' : './analyze/client.html'
})
)
}
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
}
return config
}
})
}

View file

@ -0,0 +1,13 @@
{
"name": "@next/bundle-analyzer",
"version": "0.0.1",
"main": "index.js",
"license": "MIT",
"repository": {
"url" : "zeit/next.js",
"directory": "packages/next-bundle-analyzer"
},
"dependencies": {
"webpack-bundle-analyzer": "3.0.3"
}
}

View file

@ -0,0 +1,33 @@
# Next.js + Webpack Bundle Analyzer
Use `webpack-bundle-analyzer` in your Next.js project
## Installation
```
npm install --save @next/bundle-analyzer
```
or
```
yarn add @next/bundle-analyzer
```
### Usage with environment variables
Create a next.config.js (and make sure you have next-bundle-analyzer set up)
```js
const withBundleAnalyzer = require("@next/bundle-analyzer")({ enabled: process.env.ANALYZE === "true" });
module.exports = withBundleAnalyzer({});
```
Then you can run the command below:
```bash
# Analyze is done on build when env var is set
ANALYZE=true yarn build
```
When enabled two HTML files (client.html and server.html) will be outputted to `<distDir>/analyze/`. One will be for the server bundle, one for the browser bundle.