Node Modules
#node #npm #packages
node_modules is where node keeps all their dependencies
one good thing of node_modules is that you can easily modify an external package code inside node_modules and test your fix before sending a pull request
node_modules also applies the colocation pattern, where the dependencies are close to the project
If you check C,C++,python,ruby, GO and other, the deps are not close to where there are used. So it is much harder to modify deps and contribute back
if you use monorepo with yarn workspaces you gonna have many node_modules. One at the root and one at each package level. Yarn will hoist same package version range to the node_modules in the root.
Hoist caused many problems as most tool have the wrong assumptions that node_modules is besides the package, and also the package
if your node_modules is big it is be slow to load packages, as node tranverse the node_modules to find it
reduce node modules techniques
-
https://tsh.io/blog/reduce-node-modules-for-better-performance/
-
use
-productionflag -
node-prune / modclean
https://gist.github.com/greim/e8e1bd3b1ed08a7505ce
- move deps to devDepencies
- improve .npmignore
only pick select fields on package.json
const pickFields = [
'name',
'version',
'license',
'author',
'homepage',
'repository',
'bugs',
'keywords',
'module',
'main',
'typings',
'dependencies',
'peerDependencies',
'files',
];
Links
Colocation
- Bundle analyzeMost modern apps can’t be built without dependencies, so we need to analyze the final bundle of our application to make sure we are not shipping unnecessary code We can also use…
- Single Bin JavaScriptnode modules is too big and usually it has many things that you don’t need to use It has Readme.md It has examples It has tests and other unrelated code It would be could to…
- Memory LeakMemory leak when you allocated some memory and didn't dispose it.
- Package Sizemodules npm package sizes matters if you reduce your project dependencies your node modules will be small and it will be fast to run yarn install and also to cache and restore…
Sign in with GitHub to reply.
Select any passage to quote it.
Comments