1 | <h1>
|
2 | 👩🔬 Webpack Dependency Size Plugin
|
3 | <a href="https://npm.im/webpack-dependency-size"><img src="https://badgen.net/npm/v/webpack-dependency-size"></a>
|
4 | <a href="https://npm.im/webpack-dependency-size"><img src="https://badgen.net/npm/dm/webpack-dependency-size"></a>
|
5 | <a href="https://packagephobia.now.sh/result?p=webpack-dependency-size"><img src="https://packagephobia.now.sh/badge?p=webpack-dependency-size"></a>
|
6 | </h1>
|
7 |
|
8 | [Webpack](https://webpack.js.org) plugin to get an overview of bundled dependencies and their size.
|
9 |
|
10 | ## :raising_hand: Why?
|
11 | - 📦 **Only Dependencies** Get insight into the blackbox!
|
12 | - 🔥 **Fast** Only analyzes the bare minium!
|
13 | - 👀 **JSON Output** Formatted, sorted, and portable!
|
14 | - 🙈 **No distractions** Ignore application code!
|
15 |
|
16 | ## :rocket: Install
|
17 | ```sh
|
18 | npm i -D webpack-dependency-size
|
19 | ```
|
20 |
|
21 | ## 👩🏫 Basic Usage
|
22 | In your Webpack config:
|
23 | ```js
|
24 | // 1. Import plugin
|
25 | const DependencySize = require('webpack-dependency-size');
|
26 |
|
27 | module.exports = {
|
28 | ...,
|
29 |
|
30 | plugins: [
|
31 | // 2. Add to plugins array
|
32 | new DependencySize()
|
33 | ]
|
34 | };
|
35 | ```
|
36 |
|
37 | ### Options
|
38 | Pass in an options object to configure:
|
39 | ```js
|
40 | new DependencySize({
|
41 | // Options
|
42 | gzip: true
|
43 | })
|
44 | ```
|
45 | - `outputPath` (`dependency-size.json`) JSON output path relative to Webpack output directory (`output.path`)
|
46 | - `gzip` (`false`) Calculate gzipped size
|
47 | - `indent` (2 spaces) JSON output indentation
|
48 |
|
49 | ## 📋 Output
|
50 |
|
51 | ### Schema
|
52 | ```js
|
53 | type File = {
|
54 | filepath: string; // bundled-in file
|
55 | size: string; // human-readable size
|
56 | reasons: string[]; // request sources
|
57 | };
|
58 |
|
59 | type Report = {
|
60 | dependencyPath: string; // bundled-in package (sorted by `size`)
|
61 | size: string; // human-readable net import size from package
|
62 | files: File[]; // specific files imported from the package (sorted by `size`)
|
63 | }[];
|
64 | ```
|
65 |
|
66 | ### Example
|
67 |
|
68 | > Tip: If the output is too large, I recommend using [fx](https://github.com/antonmedv/fx) to navigate the JSON
|
69 |
|
70 | ```json5
|
71 | [
|
72 | {
|
73 | "dependencyPath": "./node_modules/axios",
|
74 | "size": "40.15 KB",
|
75 | "files": [
|
76 | {
|
77 | "filepath": "./node_modules/axios/lib/utils.js",
|
78 | "size": "8.61 KB",
|
79 | "reasons": [
|
80 | "./node_modules/axios/lib/adapters/xhr.js",
|
81 | ...
|
82 | ]
|
83 | },
|
84 | ...
|
85 | ]
|
86 | },
|
87 | {
|
88 | "dependencyPath": "./node_modules/lodash",
|
89 | "size": "25.37 KB",
|
90 | "files": [
|
91 | {
|
92 | "filepath": "./node_modules/lodash/_deburrLetter.js",
|
93 | "size": "3.33 KB",
|
94 | "reasons": [
|
95 | "./node_modules/lodash/deburr.js"
|
96 | ]
|
97 | },
|
98 | ...
|
99 | ]
|
100 | },
|
101 | ...
|
102 | ]
|
103 | ```
|
104 |
|
105 | ## 👨👩👦👦 Related
|
106 |
|
107 | - [webpack-distsize](https://github.com/privatenumber/webpack-distsize) - Track Webpack output size via version control
|
108 | - [webpack-analyze-duplication-plugin](https://github.com/privatenumber/webpack-analyze-duplication-plugin) - Webpack plugin to detect duplicated modules
|
109 |
|
110 |
|
111 | ## 💼 License
|
112 | MIT
|