7

I am new, and when i first created my app based on the documentation using npm create-react-app i found it there were a lot of package included inside folder node_module when i code and i only use react and react DOM and etc from the basic.

node_modules
 acorn
 timer
 ansi
 and many more

I wonder if anyone can help my how to understand each use inside the node_module or where can i find the documentation for each use?

or how can i just reduce to what i want to use only to decrease the app size?

Hitmands
  • 13,491
  • 4
  • 34
  • 69
Michael Vinci
  • 105
  • 1
  • 8
  • 1
    Your question is about npm, not Node.js or React. See [Installing npm packages locally](https://docs.npmjs.com/getting-started/installing-npm-packages-locally). – E_net4 Jun 26 '17 at 12:39
  • Possible duplicate of [What is node\_modules directory in AngularJS?](https://stackoverflow.com/questions/34526844/what-is-node-modules-directory-in-angularjs) – Yosef Weiner Jun 26 '17 at 12:40
  • Possible duplicate of [Where does npm install packages?](https://stackoverflow.com/questions/5926672/where-does-npm-install-packages) – E_net4 Jun 26 '17 at 12:41
  • @E_net4 i think its close to the answer but can u tell me where can i find the lib and each use for react? – Michael Vinci Jun 27 '17 at 02:20

2 Answers2

3

The answers are 2:

  1. because you're using an automated scaffolding tool, which essentially does everything for you, and, you have just to code, it is supposed to locally deploy all the packages it needs to work (for example webpack is needed to bundle your code, babel to transpile it, ...
  2. under node_modules you will find all the packages of the whole app. That's means you will find both your dependencies and the dependencies of your dependencies (this rule has some exceptions and you can find them in the npm documentation.

example:

// your code depends on A

var dependency = require('A');

// but then, inside your A dependency you can also find something similar to:

var b = require('B');

how can i just reduce to what i want to use only to decrease the app size?

You basically can't do it. They are all needed.

Hitmands
  • 13,491
  • 4
  • 34
  • 69
  • so i need to first deploy it locally? where can i find the documentation about what i need only to use in react so all of those 100++mb in node_modules can be reduced? – Michael Vinci Jun 27 '17 at 02:19
  • You can't reduce your amount, as I said **all of them are needed**, but you can always develop as we were doing in 1990, just include `React` in your html via some `cdn` and that's it. – Hitmands Jun 27 '17 at 08:29
2

Most of the libraries that we pull from npm have dependencies. You may use only react and react-dom but there are react-scripts that require lots of stuff. I don't think that you have to worry about the size of the node_modules. That's not what you are suppose to ship in production.

If you want to see what are these all modules about you may open their folder and fine README.md file.

Krasimir
  • 13,306
  • 3
  • 40
  • 55
  • if i want to delete what i dont need should i just delete it in node_modules ? – Michael Vinci Jun 27 '17 at 02:20
  • If it happens that there's something that you don't use you are free to delete it from node_modules. You can always bring it back by calling `npm install` or `yarn install` (if you use yarn). The thing is that sometimes is difficult to say if you need or no something from this folder. Why not cleaning your package.json file, delete node_modules entirely and install again. Then you'll have only those modules that are in the package.json. – Krasimir Jun 29 '17 at 12:01