Git Product home page Git Product logo

cost-of-modules's Introduction

Cost of modules

Find out which of your dependencies is slowing you down

Build Status npm

Find out which of your dependencies is causing bloat

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

โญ this repo

Motivation

I recently published a npm module (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.

  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.

That's the reason why I created this tool.

--

Future

I would want to make this tool a pre-publish checklist.

  • 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

License

MIT ยฉ siddharthkp

cost-of-modules's People

Contributors

mattecapu avatar siddharthkp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.