Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node_modules has too many files when using react framework

When I use react framework and I do a npm install, about 27,000 files are generated on my node_modules. The size is not the concern, rather, the amount of files. If I have to copy that directory somewhere else, it takes a very long time due to that many files. If I have to delete it, that takes long as well. My Google drive sync does not have an "exclude folder" option for node_modules, therefore, syncing that with cloud also takes a VERY long time. I also don't like the fact that each react project I have, will generate another 27,000 files.

Does anyone have a solution for this? Basically, I don't want 27,000 files for every react project I create. I was thinking of just having one GLOBAL node_modules somewhere and ALL react apps will call that instead of creating their own node_modules folder.

Here is my package.json

{
  "name": "react-typescript-tutorial",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.0",
    "enzyme": "^3.3.0",
    "react": "^16.4.1",
    "react-bootstrap": "^0.32.1",
    "react-dom": "^16.4.1",
    "react-redux": "^5.0.2",
    "react-router-dom": "^4.3.1",
    "react-router-redux": "^5.0.0-alpha.9",
    "redux": "^4.0.0",
    "redux-thunk": "^2.3.0"
  },
  "scripts": {
    "start": "react-scripts-ts start",
    "build": "react-scripts-ts build",
    "test": "react-scripts-ts test --env=jsdom",
    "eject": "react-scripts-ts eject"
  }
}

P.S. I'm willing to change to a different package manager like yarn or whatever, if it can generate less files.

like image 844
FerX32 Avatar asked Jul 10 '18 16:07

FerX32


2 Answers

I'm considering learning something else.

Elm sounds promising for organized and tidy filesystem. And googles polymer-project aim to change the web into not needing any framework at all.

like image 95
agiopnl Avatar answered Nov 04 '22 16:11

agiopnl


Try this:

  1. Install all of your dependencies in global.
  2. Go to each module of it (just module in dependencies ) and run npm link you registed that module.
  3. Go to your project and run npm link <name module need link>
  4. Done, npm created link to your dependencies

I don't Google drive sync it or not, but npm don't need install it.

You can try Exclude folder in Folder or Exclude subfolder from sync, but keep this folder in PC

Or you don't use npm install to install module. You should install global for all and set enviroment variable NODE_PATH to global node_modules. When require, node will call it.

like image 28
hong4rc Avatar answered Nov 04 '22 16:11

hong4rc