It may seem obvious, but many projects carry a lot of dead weight. Here is an example of Disk Inventory X analyzing a node_modules folder: 4 Remove unused dependencies Bundlephobia: Check how big a package usually is when bundled in an app.Packagephobia: Use it to see roughly how big a package is on disk.It lists all the other packages that depend on it and which versions they depend on. yarn why : This command explains why a specific package ended up in your dependency tree.node_modules/* | sort -nr | grep '\dM.*' 3 to analyze the size of dependencies in node_modules. I haven’t found a good all-in-one solution to analyze a node_modules folder, so instead, we’ll use four different ones: We’ll analyze our dependencies using various methods. Alright? Let’s dive in! Analyze dependenciesįirst, we need to get an understanding of what kind of packages are in our node_modules folders. Let’s take it for granted that materialized files on the file system are the only way to go, just like first-party code is stored on a file system and in version control. I have also seen death by a thousand cuts at scale with those solutions. I have tried some of them and was involved in the creation of another. One thing to keep in mind is that some package managers will use symlinks, hard links or other tricky and opaque ways to avoid installing dependencies directly. This guide primarily focuses on Yarn 1, but many recommendations will equally apply to other package managers. Track the number and size of dependencies.Align on a single package for a well-defined purpose.We gain option value and control by removing dependencies or by actively maintaining them. Yes, third-party dependencies undoubtedly help us move fast initially, but using them means we lose control over our stack. example is reducing external dependencies or choosing them more carefully. What would it look like if we took ownership of our dependencies? As discussed in a previous post about Principles of Developer Experience: Applying the below methods reduced the size of third-party dependencies within Facebook’s React Native codebase by an order of magnitude, improved install times by an equal factor, and sustained the wins. Adding many large dependencies tends to slow down install times significantly 2 and make all operations slower for everyone globally, even if individuals only use a subset of tools in a project. Many tools will analyze, parse, process or do something with files in a node_modules folder. Instead, I’m hoping to provide a definite guide to avoiding black holes on your hard drive 1 and gain control over your third-party dependencies. This article won’t solve the fundamental problems of package managers. Instead, they are primarily convenient tools to download and extract artifacts with a few task runner capabilities sprinkled in. Existing JavaScript dependency managers are actually not very good at managing dependencies. However, their ease of use and the high modularization of packages come with many downsides. They enable the constant search for novel solutions in the front-end space. JavaScript Dependency Managers such as npm, Yarn, or pnpm have had a tremendous impact on the JavaScript ecosystem’s evolution. You can also listen via Apple Podcasts, Pocket Casts, or others.
0 Comments
Leave a Reply. |