Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 3: Split reporting UI from dependency graph size calculation #97

Closed
wants to merge 71 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
bed16d6
Trim trailing whitespace in analyzer bin
valscion May 27, 2017
92725f7
Move chartData calculation to outer layer of code
valscion May 27, 2017
013cec6
Pass logger instance form bin to viewer
valscion May 27, 2017
6324701
Force the presence of logger in viewer functions
valscion May 27, 2017
8a78d1b
Force the presence of logger in analyzer functions
valscion May 27, 2017
7484107
Move client and views directories under reporter root directory
valscion May 27, 2017
1887ecb
Remove start from main entry point
valscion May 27, 2017
14068fa
Update changelog with unreleased changes
valscion May 27, 2017
59c3926
Update package.json files array to match reporter changes
valscion May 27, 2017
4f405cf
Merge branch 'master' into split-reporter-2
valscion Jul 14, 2017
318f588
Merge pull request #81 from th0r/split-reporter-2
valscion Jul 14, 2017
0dea700
Run lerna init
valscion Jul 14, 2017
d218b3e
Move code-related files 1:1 under packages/webpack-bundle-analyzer-pl…
valscion Jul 14, 2017
9d2e4d3
Add root-level package.json
valscion Jul 14, 2017
88c4256
Configure lerna to use yarn as npm client
valscion Jul 14, 2017
3d4f895
Move lerna dep to root-level package.json
valscion Jul 14, 2017
2cb55a6
Use exact version for lerna
valscion Jul 14, 2017
e579dad
Run yarn in root of repo
valscion Jul 14, 2017
31b443b
Add some info about lerna to CONTRIBUTING.md
valscion Jul 14, 2017
a18dc45
Split Treemap reporter to new package
valscion Jul 14, 2017
14b6356
Update .gitignore to work with monorepo
valscion Jul 14, 2017
aab16e4
Move linting setup to root level
valscion Jul 14, 2017
c6afe54
Run bootstrap in CI
valscion Jul 14, 2017
8af93ed
Replace global lerna usage instruction with npm script
valscion Jul 14, 2017
2ae76b4
Cache sub-package node_modules in TravisCI as well
valscion Jul 14, 2017
0c7403f
v3.0.0-alpha.0
valscion Jul 14, 2017
ad1304f
Merge pull request #98 from th0r/lerna
valscion Jul 14, 2017
b45c783
Fix .gitignore being too eager
valscion Jul 14, 2017
a62bcad
Merge pull request #99 from th0r/fix-git-ignore
valscion Jul 14, 2017
dcd2336
Point URLs in reporter-treemap package.json to main repo
valscion Jul 14, 2017
d7c74f1
Remove unnecessary reporter/ subdir in reporter package
valscion Jul 14, 2017
2b96d9a
Remove obsolete reporter-related package.json/files setup in plugin
valscion Jul 14, 2017
c259b77
Merge pull request #100 from th0r/clean-up-reporter
valscion Jul 14, 2017
5806437
Add npm run dev script
valscion Jul 14, 2017
b7906da
Move publish script to root package
valscion Jul 15, 2017
560339d
Stream output of tests while running
valscion Jul 15, 2017
5ffe9d9
Merge pull request #101 from th0r/improve-dev-experience
valscion Jul 15, 2017
6de3a6b
Move plugin code to @webpack-bundle-analyzer/plugin npm package
valscion Jul 15, 2017
a8d8b91
Run yarn in every package
valscion Jul 15, 2017
f6d99c0
v3.0.0-alpha.1
valscion Jul 15, 2017
1826eae
Remove deprecated startAnalyzer plugin option
valscion Jul 15, 2017
1498e7c
Add --reporter and --reporterOptions to configure reporter
valscion Jul 15, 2017
82780ca
Add test-dev npm script
valscion Jul 17, 2017
e989f78
Define static report output path on the outer edge
valscion Jul 17, 2017
1d97eec
Move process.cwd() fallback for outputPath to plugin
valscion Jul 17, 2017
ebf60e7
Always set CLI outputPath as current working directory
valscion Jul 17, 2017
a72fccd
Remove outputPath fallback from plugin code
valscion Jul 17, 2017
e3a70d5
Fix test invocations
valscion Jul 17, 2017
e73619d
Remove unnecessary tmp directory setup for dev-server tests
valscion Jul 17, 2017
fec9b6d
Merge pull request #102 from th0r/new-options
valscion Jul 17, 2017
d4e1915
Merge master to version-3 branch to bring it up-to-date (#117)
valscion Sep 24, 2017
17ef047
Merge branch 'master' into version-3
valscion Sep 24, 2017
b881a78
Upgrade lerna to v2.2.0
valscion Sep 24, 2017
11a930e
Point nightmare package to a version that pins electron
valscion Sep 24, 2017
e4440a0
Configure lerna and yarn to use workspaces
valscion Sep 24, 2017
214d7cb
Remove yarn.lock from sub-deps to have it only on root level
valscion Sep 24, 2017
2cefa35
Configure Travis to use [email protected]
valscion Sep 24, 2017
9bc8b43
Merge pull request #118 from th0r/yarn-workspaces-and-version-1
valscion Sep 24, 2017
6e02730
Merge commit 'ce41c97' into version-3
valscion Dec 9, 2017
57b341f
Merge commit 'e6fbbe7' into version-3
valscion Dec 9, 2017
40c06e7
Merge commit 'ceef5be' into version-3
valscion Dec 9, 2017
082bb9a
Merge branch 'master' into version-3
valscion Dec 9, 2017
d73ea19
Merge branch 'master' into version-3
valscion Jan 13, 2018
9ea963d
Setup viewer specific tests properly
valscion Jan 13, 2018
acbc837
Merge commit '5cb03bad2195506189c2cefedbf601fd5d3252f7' into version-3
valscion Feb 4, 2018
282c1e1
Merge branch 'master' into version-3
valscion Feb 4, 2018
61dabf9
Run CI for pull requests targeting version-3 branch
valscion Feb 4, 2018
faf24a3
Split bundle parsing to new package (#143)
valscion Feb 4, 2018
15caf72
Extract Logger class to own package (#151)
valscion Feb 4, 2018
241f500
v3.0.0-alpha.2
valscion Feb 4, 2018
b63ca72
Fix bundle-parser README.md API example
valscion Feb 4, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# node_modules in sub-packages
packages/*/node_modules

# Generated code
lib
public
packages/*/lib
packages/reporter-treemap/public

# Vendor code
client/vendor
packages/reporter-treemap/client/vendor

# Test fixtures
test/bundles
test/webpack.config.js
packages/*/test/bundles
packages/*/test/webpack.config.js

# Test results
test/output
packages/*/test/output

samples
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
lib
public
# node_modules in sub-packages
packages/*/node_modules

# Generated code
packages/*/lib
packages/reporter-treemap/public

samples

node_modules
npm-debug.log
lerna-debug.log
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sudo: false
branches:
only:
- master
- version-3
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be removed right before merging. This is needed here so that branches against this version-3 branch have their tests ran in CI. See #143 (comment)

node_js:
- "4"
- "6"
Expand All @@ -12,13 +13,18 @@ cache:
- yarn: true
- directories:
- node_modules
- packages/bundle-parser/node_modules
- packages/reporter-treemap/node_modules
- packages/plugin/node_modules
addons:
apt:
packages:
# Required by Electron
# https://github.com/juliangruber/electron-stream#travis
- xvfb
before_script:
# Install packages in subdirectories
- npm run bootstrap
# Required by Electron
- export DISPLAY=':99.0'
- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ _Note: Gaps between patch versions are faulty, broken or test releases._

<!-- Add changelog entries for new changes under this section -->

* **Internal**
* Moved internal, treemap reporter related code around (@valscion at [#81](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/81)).
* Removed undocumented `require('webpack-bundle-analyzer').start` accessor. If you try to
use the `start` function now, it will raise an error.

## 2.10.0

* **Bug Fix**
Expand Down
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ To contribute to `webpack-bundle-analyzer`, fork the repository and clone it to

## Setup packages

Then install [`yarn`](https://yarnpkg.com/):
Install [`yarn`](https://yarnpkg.com/):

```sh
npm install --global yarn
Expand All @@ -16,6 +16,12 @@ Next, install this package's dependencies with `yarn`:
yarn install
```

Bootstrap the Lerna project (installs all node_modules in monorepo packages)

```sh
npm run bootstrap
```

## Develop with your own project

Run the following to build this library and watch its source files for changes:
Expand Down
6 changes: 6 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"lerna": "2.0.0",
"npmClient": "yarn",
"useWorkspaces": true,
"version": "3.0.0-alpha.2"
}
93 changes: 13 additions & 80 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,90 +1,23 @@
{
"name": "webpack-bundle-analyzer",
"version": "2.10.0",
"description": "Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap",
"author": "Yury Grunin <[email protected]>",
"license": "MIT",
"homepage": "https://github.com/webpack-contrib/webpack-bundle-analyzer",
"changelog": "https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/master/CHANGELOG.md",
"bugs": {
"url": "https://github.com/webpack-contrib/webpack-bundle-analyzer/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/webpack-contrib/webpack-bundle-analyzer.git"
},
"main": "lib/index.js",
"bin": "lib/bin/analyzer.js",
"engines": {
"node": ">= 4"
},
"scripts": {
"start": "gulp watch",
"build": "gulp build",
"npm-publish": "npm run lint && npm run build && npm test && npm publish",
"lint": "eslint --ext js,jsx .",
"test": "mocha --exit --require babel-core/register",
"test-dev": "mocha --watch --require babel-core/register"
},
"files": [
"public",
"lib",
"src",
"views"
"private": true,
"workspaces": [
"packages/*"
],
"dependencies": {
"acorn": "^5.3.0",
"bfj-node4": "^5.2.0",
"chalk": "^2.3.0",
"commander": "^2.13.0",
"ejs": "^2.5.7",
"express": "^4.16.2",
"filesize": "^3.5.11",
"gzip-size": "^4.1.0",
"lodash": "^4.17.4",
"mkdirp": "^0.5.1",
"opener": "^1.4.3",
"ws": "^4.0.0"
"scripts": {
"bootstrap": "lerna bootstrap",
"build": "lerna run build --stream",
"dev": "lerna run start --parallel",
"npm-publish": "npm run lint && npm run build && npm test && lerna publish",
"test": "lerna run test --stream",
"test-dev": "lerna run test-dev --parallel",
"lint": "eslint --ext js,jsx ."
},
"devDependencies": {
"babel-core": "6.26.0",
"babel-eslint": "8.2.1",
"babel-loader": "7.1.2",
"babel-plugin-transform-class-properties": "6.24.1",
"babel-plugin-transform-object-rest-spread": "6.26.0",
"babel-plugin-transform-react-jsx": "6.24.1",
"babel-preset-env": "1.6.1",
"chai": "4.1.2",
"chai-subset": "1.6.0",
"classnames": "2.2.5",
"css-loader": "0.28.9",
"del": "3.0.0",
"eslint": "4.16.0",
"eslint-config-th0r": "1.0.0",
"eslint-config-th0r-react": "1.0.0",
"eslint-plugin-react": "7.6.1",
"exports-loader": "0.6.4",
"gulp": "4.0.0",
"gulp-babel": "7.0.1",
"mocha": "5.0.0",
"nightmare": "2.10.0",
"preact": "8.2.7",
"sinon": "4.2.2",
"stream-combiner2": "1.1.1",
"style-loader": "0.20.1",
"webpack": "3.10.0",
"webpack-dev-server": "2.11.1"
},
"keywords": [
"webpack",
"bundle",
"analyzer",
"modules",
"size",
"interactive",
"chart",
"treemap",
"zoomable",
"zoom"
]
"lerna": "2.2.0"
}
}
14 changes: 14 additions & 0 deletions packages/bundle-parser/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Babel config for Node
// Compiles sources, gulpfile and tests
{
"presets": [
["env", {
"targets": { "node": 4 },
"exclude": [
// Node 4 supports all the generator features that we use so there is no need in Regenerator
"transform-regenerator"
]
}]
],
"plugins": []
}
168 changes: 168 additions & 0 deletions packages/bundle-parser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<div align="center">
<a href="https://github.com/webpack/webpack">
<img width="200" height="200"
src="https://webpack.js.org/assets/icon-square-big.svg">
</a>
<h1>@webpack-bundle-analyzer/bundle-parser</h1>
<p>Calculates module sizes from webpack output files.</p>
</div>

<h2 align="center">Install</h2>

```bash
npm install --save @webpack-bundle-analyzer/bundle-parser
```

<h2 align="center">Usage</h2>

```js
const parseBundle = require('@webpack-bundle-analyzer/bundle-parser');
const Logger = require('@webpack-bundle-analyzer/logger');

const fs = require('fs');
const webpackStats = JSON.parse(
fs.readFileSync('webpack/output/path/stats.json', 'utf8')
);

const moduleSizeData = parseBundle(
webpackStats,
'webpack/output/path',
{ logger: new Logger('info') }
);

console.log(JSON.stringify(moduleSizeData, null, 2));
```

Example output:

```json
[
{
"label": "bundle.js",
"statSize": 141,
"parsedSize": 445,
"gzipSize": 178,
"groups": [
{
"label": "my-app",
"path": "./my-app",
"statSize": 141,
"parsedSize": 332,
"gzipSize": 119,
"groups": [
{
"label": "src",
"path": "./my-app/src",
"statSize": 141,
"parsedSize": 332,
"gzipSize": 119,
"groups": [
{
"id": 0,
"label": "index.js",
"path": "./my-app/src/index.js",
"statSize": 54,
"parsedSize": 131,
"gzipSize": 93
},
{
"id": 1,
"label": "a.js",
"path": "./my-app/src/a.js",
"statSize": 29,
"parsedSize": 67,
"gzipSize": 73
},
{
"id": 2,
"label": "b.js",
"path": "./my-app/src/b.js",
"statSize": 29,
"parsedSize": 67,
"gzipSize": 73
},
{
"id": 3,
"label": "a-clone.js",
"path": "./my-app/src/a-clone.js",
"statSize": 29,
"parsedSize": 67,
"gzipSize": 73
}
]
}
]
}
]
}
]
```


<h2 align="center">Options</h2>

```js
parseBundle(
bundleStats: object,
bundleDir: string,
options: {
logger: Logger
}
);
```

|Name|Type|Description|
|:--:|:--:|:----------|
|**`bundleStats`**|`{Object}`|webpack compilation information as a JSON object. This is the output of [`stats.toJson()`](https://webpack.js.org/api/node/#stats-tojson-options-) webpack Node.js API.|
|**`bundleDir`**|`{String}`|Path to directory containing webpack output files, i.e. the value of [`output.path` webpack config](https://webpack.js.org/configuration/output/#output-path).|
|**`options.logger`**|`{Logger}`|An instance of a special `Logger` class also used in `webpack-bundle-analyzer`.|



<h2 align="center" id="size-definitions">Size definitions</h2>

Data contains three sizes for each module if bundle parsing has succeeded, or only `statSize` if bundle parsing has failed for some reason.

### `statSize`

The "input" size of modules, before any transformations like minification.

### `parsedSize`

The "output" size of modules. If you're using a webpack plugin such as Uglify, then this value will reflect the minified size of your code.

### `gzipSize`

Size approximation of running the parsed modules through gzip compression.

Gzip sizes of folders are calculated by concatenating the parsed sources of all modules inside a folder and running [`gzip-size`](https://github.com/sindresorhus/gzip-size) over it.


<h2 align="center">Troubleshooting</h2>

### Some inner modules are missing from the data

This is a known caveat when `webpack.optimize.ModuleConcatenationPlugin` is used. The way `ModuleConcatenationPlugin` works is that it merges multiple modules into a single one, and so that resulting module doesn't have edges anymore.

If you are interested to drill down to exact dependencies, try parsing output without `ModuleConcatenationPlugin` applied. See [issue #115](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/115) for more discussion.

<h2 align="center">Maintainers</h2>

<table>
<tbody>
<tr>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/302213?v=4&s=150">
</br>
<a href="https://github.com/th0r">Yuriy Grunin</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/482561?v=4&s=150">
</br>
<a href="https://github.com/valscion">Vesa Laakso</a>
</td>
</tr>
<tbody>
</table>
Loading