Skip to content

Commit 89498b3

Browse files
committed
Initial v2 commit using metro & source-map-explorer
1 parent 8f73cd6 commit 89498b3

10 files changed

Lines changed: 607 additions & 95 deletions

README.md

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,19 @@
22

33
See what's inside of your react-native bundle 📦
44

5-
![bundle-visualizer-animation](./react-native-bundle-visualizer.gif)
5+
![bundle-visualizer-animation](./react-native-bundle-visualizer2.gif)
66

7-
Uses the awesome [webpack-visualizer](https://github.com/chrisbateman/webpack-visualizer) and [haul](https://github.com/callstack-io/haul) bundler.
7+
Uses the awesome [source-map-explorer](https://github.com/danvk/source-map-explorer) to visualize the output of the [Metro bundler](https://github.com/facebook/metro).
88

99
## Purpose
1010

1111
Sometimes, importing a single javascript library can drastically increase your bundle size. This package helps you to identify such a library, so you can keep the bundle size low and loading times fast.
1212

1313
## Usage
1414

15-
*Make sure you have node 8 or higher installed.*
15+
Install as a dev-dependency:
1616

17-
Depending on your react-native version, install the appropriate package as a dev dependency:
18-
19-
| RN version | Install react-native-bundle-visualizer |
20-
|-------------|------------|
21-
| >= 0.57 | `yarn add --dev react-native-bundle-visualizer` |
22-
| 0.49 - 0.56 | `yarn add --dev react-native-bundle-visualizer@1.3.5` |
23-
| <= 0.48 | `yarn add --dev react-native-bundle-visualizer@1.1.0` |
17+
`yarn add --dev react-native-bundle-visualizer`
2418

2519
And run it:
2620

@@ -31,22 +25,13 @@ And run it:
3125
npm install --save-dev react-native-bundle-visualizer
3226
./node_modules/.bin/react-native-bundle-visualizer
3327

34-
### Gitignore output files
3528

36-
Additionally, add the haul generated files & folders to your `.gitignore` file:
29+
## Usage with older react-native versions and the Haul bundler
3730

38-
```
39-
# Haul bundler
40-
/assets
41-
stats.html
42-
index.ios.bundle
43-
index.ios.bundle.map
44-
haul-debug.log
45-
```
31+
As of `react-native-bundle-visualizer` version 2.x, the direct output of the [Metro bundler](https://github.com/facebook/metro) is visualized using the [source-map-explorer](https://github.com/danvk/source-map-explorer).
4632

47-
## Disclaimer
33+
Prior to version 2, the Haul bundler was used which used Webpack. If you are having problems visualizing the output for older react-native versions, or you want to explicitly use the Haul bundler, [please check out the V1 documentation]('./README_v1.md).
4834

49-
The sizes reported are an indication rather than the exact byte size in your bundle. This is because the Haul packager returns different bundles compared to the react-native Metro bundler. Also, due to limitations in webpack's stats, the "actual" (minified) numbers reported here are approximate, but they should be pretty close.
5035

5136
## License
5237

README_v1.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# react-native-bundle-visualizer
2+
3+
See what's inside of your react-native bundle 📦
4+
5+
![bundle-visualizer-animation](./react-native-bundle-visualizer.gif)
6+
7+
Uses the awesome [webpack-visualizer](https://github.com/chrisbateman/webpack-visualizer) and [haul](https://github.com/callstack-io/haul) bundler.
8+
9+
## Purpose
10+
11+
Sometimes, importing a single javascript library can drastically increase your bundle size. This package helps you to identify such a library, so you can keep the bundle size low and loading times fast.
12+
13+
## Usage
14+
15+
*Make sure you have node 8 or higher installed.*
16+
17+
Depending on your react-native version, install the appropriate package as a dev dependency:
18+
19+
| RN version | Install react-native-bundle-visualizer |
20+
| ----------- | ----------------------------------------------------- |
21+
| >= 0.57 | `yarn add --dev react-native-bundle-visualizer@1` |
22+
| 0.49 - 0.56 | `yarn add --dev react-native-bundle-visualizer@1.3.5` |
23+
| <= 0.48 | `yarn add --dev react-native-bundle-visualizer@1.1.0` |
24+
25+
And run it:
26+
27+
yarn run react-native-bundle-visualizer
28+
29+
*or when using npm:*
30+
31+
npm install --save-dev react-native-bundle-visualizer
32+
./node_modules/.bin/react-native-bundle-visualizer
33+
34+
### Gitignore output files
35+
36+
Additionally, add the haul generated files & folders to your `.gitignore` file:
37+
38+
```
39+
# Haul bundler
40+
/assets
41+
stats.html
42+
index.ios.bundle
43+
index.ios.bundle.map
44+
haul-debug.log
45+
```
46+
47+
## Disclaimer
48+
49+
The sizes reported are an indication rather than the exact byte size in your bundle. This is because the Haul packager returns different bundles compared to the react-native Metro bundler. Also, due to limitations in webpack's stats, the "actual" (minified) numbers reported here are approximate, but they should be pretty close.
50+
51+
## License
52+
53+
[MIT](./LICENSE.txt)
54+

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
"author": "IjzerenHein <hrutjes@gmail.com>",
66
"keywords": [
77
"react-native-bundle-visualizer",
8+
"react native bundle size",
89
"react-native",
910
"react native",
1011
"bundle",
1112
"visualizer",
1213
"size",
1314
"bundle-size"
1415
],
15-
"bin": "./src/react-native-bundle-visualizer.sh",
16+
"bin": "./src/react-native-bundle-visualizer.js",
1617
"repository": "https://github.com/IjzerenHein/react-native-bundle-visualizer",
1718
"bugs": "https://github.com/IjzerenHein/react-native-bundle-visualizer/issues",
1819
"license": "MIT",
1920
"dependencies": {
20-
"haul": "^1.0.0-rc.15",
21-
"react-dom": "^16.8.4",
22-
"react-hot-loader": "^4.8.0",
23-
"webpack-visualizer-plugin": "^0.1.11"
21+
"execa": "^2.0.3",
22+
"minimist": "^1.2.0",
23+
"source-map-explorer": "^2.0.1"
2424
}
2525
}

src/get-entry-point.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/haul.config.extend.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/haul.config.js

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env node
2+
const fs = require('fs');
3+
const tmpdir = require('os').tmpdir() + '/react-native-bundle-visualizer';
4+
const argv = require('minimist')(process.argv.slice(2));
5+
const execa = require('execa');
6+
7+
function getEntryPoint() {
8+
const pkgJSON = JSON.parse(fs.readFileSync('./package.json'));
9+
let entry = pkgJSON.main || 'index.js';
10+
if (entry[0] !== '.' && entry[0] !== '/' && entry[0] !== '\\') {
11+
entry = './' + entry;
12+
}
13+
return entry;
14+
}
15+
16+
// Get (default) arguments
17+
const entryFile = argv['entry-file'] || getEntryPoint();
18+
const platform = argv.platform || 'ios';
19+
const dev = argv.dev || false;
20+
const bundleOutput =
21+
argv['bundle-output'] || tmpdir + '/' + platform + '.bundle';
22+
const bundleOutputSourceMap = bundleOutput + '.map';
23+
24+
// Make sure output dir exists
25+
if (!fs.existsSync(tmpdir)) fs.mkdirSync(tmpdir);
26+
27+
// Start
28+
const bundlePromise = execa('./node_modules/.bin/react-native', [
29+
'bundle',
30+
'--platform',
31+
platform,
32+
'--dev',
33+
dev,
34+
'--entry-file',
35+
entryFile,
36+
'--bundle-output',
37+
bundleOutput,
38+
'--sourcemap-output',
39+
bundleOutputSourceMap
40+
]);
41+
bundlePromise.stdout.pipe(process.stdout);
42+
bundlePromise.then(() => {
43+
const explorerPromise = execa('./node_modules/.bin/source-map-explorer', [
44+
bundleOutput,
45+
bundleOutputSourceMap
46+
]);
47+
explorerPromise.stdout.pipe(process.stdout);
48+
});

src/react-native-bundle-visualizer.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/webpack.haul.extend.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)