Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/siddharthkp/cost-of-modules
Find out which of your dependencies are slowing you down 🐢
https://github.com/siddharthkp/cost-of-modules
Last synced: 1 day ago
JSON representation
Find out which of your dependencies are slowing you down 🐢
- Host: GitHub
- URL: https://github.com/siddharthkp/cost-of-modules
- Owner: siddharthkp
- License: mit
- Created: 2016-10-27T22:23:19.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2023-07-24T21:35:43.000Z (over 1 year ago)
- Last Synced: 2024-10-29T15:39:00.541Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 474 KB
- Stars: 2,842
- Watchers: 24
- Forks: 42
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nodejs-cn - cost-of-modules - 查找使性能降低的依赖 (包 / 命令行程序)
- awesome-nodejs-cn - cost-of-modules - **star:2842** 找出哪些依赖在拖慢速度 ![star > 2000][Awesome] (包 / 命令行程序)
- awesome-github-star - cost-of-modules
- awesome-nodejs - cost-of-modules - Find out which dependencies are slowing you down. (Packages / Command-line apps)
- awesome-nodejs - cost-of-modules - Find out which of your dependencies are slowing you down - ★ 2263 (Command-line apps)
- awesome-node - cost-of-modules - Find out which dependencies are slowing you down. (Packages / Command-line apps)
- awesome-nodejs-cn - cost-of-modules - 找出哪些依赖性使项目性能降低的库. (目录 / 命令行应用)
README
### Cost of modules
Find out which of your dependencies is slowing you down
[![Build
Status](https://api.travis-ci.org/siddharthkp/cost-of-modules.svg?branch=master)](https://travis-ci.org/siddharthkp/cost-of-modules)
[![npm](https://img.shields.io/npm/v/cost-of-modules.svg?maxAge=3600)](https://www.npmjs.com/package/cost-of-modules)
[![npm](https://img.shields.io/npm/dt/cost-of-modules.svg?maxAge=3600)](https://www.npmjs.com/package/cost-of-modules)
#### Sponsor
[![Sponsor](https://app.codesponsor.io/embed/LhLT2c31ydJzdLUuSR9f8mCA/siddharthkp/cost-of-modules.svg)](https://app.codesponsor.io/link/LhLT2c31ydJzdLUuSR9f8mCA/siddharthkp/cost-of-modules)
![Find out which of your dependencies is causing bloat](https://raw.githubusercontent.com/siddharthkp/cost-of-modules/master/screenshot.jpg)
#### Install
`npm install -g cost-of-modules`
#### Usage
Run `cost-of-modules` in the directory you are working in.
#### Options
`--less` Show the biggest 10 modules
`--yarn` Use yarn instead of npm to install dependencies
`--no-install` Skip installation
`--include-dev` Include devDependencies as well - for 🚀 collaborator experience
#### Show your support
:star: this repo
#### Motivation
I recently published a npm module ([auto-install](https://github.com/siddharthkp/auto-install)) and I wanted to know how many bytes am I making people download before they can use it. Turns out, it was a whopping 30M!
__More than space on disk, I want to optimise for install speed - setup is part of the user experience__
--
Now, there are 3 things that you can do to make your npm package smaller
1. Make sure all your workflow tools are in `devDependencies` and not in `dependencies` These include your build tools, testing frameworks, etc. Only `dependencies` get installed when someone installs your package. (That being said, for better collaborator experience, you should optimise for both)
2. Only include the files you need by using `files` in your `package.json` or by including a `.npmignore`. [More on that here.](https://docs.npmjs.com/files/package.json#files)
3. Use packages which do the job and take the least amount of space. For example, I realised that I did not need `yargs`, I only needed their parser `yargs-parser` which is much smaller.
4. Bonus: Bundle all your code together and strip out the functions that you don't use - I still have to try this out. This could be the most impactful one.
--
In my case, the big size was because of # 3, the bunch of npm packages that I was using.
__You can't fix what you can't measure__
With npm 2.x, it was easy to find how much space is each of your dependencies taking. You could just look at the size of each directory in `node_modules`
With npm 3, the packages are installed in flat manner, so [it isn't so straightforward](https://github.com/npm/npm/issues/10361).
That's the reason why I created this tool.
--
__Future__
I would want to make this tool a pre-publish checklist.
- [x] See the size of your `node_modules`
- [ ] Include the size of your files
- [ ] Check if `files` or `.npmignore` exists
- [ ] Check if there are any `dev dependencies` that are specified as `dependencies` (tricky)
- [ ] Compare size with the last release. Something like this:
![Warning](https://raw.githubusercontent.com/siddharthkp/cost-of-modules/master/warning.png)#### License
MIT © [siddharthkp](https://github.com/siddharthkp)