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:
parent
cc2b7bc8fa
commit
42cff0a09c
3 changed files with 66 additions and 0 deletions
20
packages/next-bundle-analyzer/index.js
Normal file
20
packages/next-bundle-analyzer/index.js
Normal 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
|
||||
}
|
||||
})
|
||||
}
|
13
packages/next-bundle-analyzer/package.json
Normal file
13
packages/next-bundle-analyzer/package.json
Normal 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"
|
||||
}
|
||||
}
|
33
packages/next-bundle-analyzer/readme.md
Normal file
33
packages/next-bundle-analyzer/readme.md
Normal 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.
|
Loading…
Reference in a new issue