Reduce node_modules size for production

I created node_modules to upload an addon to the site from localhost using ngrok and use npm install in CommandPrompt. But the created node_modules folder size was 78 MB. In this case, I have to reduce the size by deleting unwanted folders, so I browsed the internet and got two suggestions, as it might be effective for reducing the size: they use - production mode and the other uses shrinkwrap .

As a first step, I used the command npm install --production and npm install --only = production as stated here: How do I prevent the installation of "devDependencies"? NPM for Node.js (package.json)? but I don't see any changes in the folder size.

Then it went over how to use shrinkwrap to shrink the size listed on this site and tried it: https://docs.npmjs.com/cli/shrinkwrap but it didn't succeed.

Also, I mentioned here: https://www.npmjs.com/package/modclean where modclean -n default: safe command is used, I shrunk 10-11m .

But I have a large number of unwanted folders in node_modules. I have specified several required dependencies in package.json like this:

"dependencies": {
    "atlassian-connect-express": "2.0.0",
    "body-parser": "^1.14.2",
    "compression": "^1.6.0",
    "cookie-parser": "^1.4.0",
    "errorhandler": "^1.4.2",
    "express": "^4.13.3",
    "express-hbs": "*",
    "jugglingdb-sqlite3": "0.0.5",
    "morgan": "^1.6.1",
    "static-expiry": ">=0.0.5"
}

      

The dependencies I gave in package.json are multiple, but I see large sets of folders created in node_modules. How can I reduce the size of node_modules, is there another process?

+3


source to share


1 answer


As with NPM v3, all dependencies in your application are kept at the top level of yours whenever possible node_modules

- this makes it easier for NPM to remove duplicates and prevents some nasty "paths too long" bugs on Windows.

It is important to understand that when I say "all dependencies in your application" I mean not only those in yours package.json

- all these packages will also have their own dependencies (and their dependencies may have their own dependencies, etc.) ). This is why it node_modules

always has so many folders inside.



As an example - it express

has 28 dependencies, so yours node_modules

would have at least 29 folders if that was the only one you installed - and that's without considering subdependencies.

So, to answer your question - apart from the things you mentioned, you can't make yours node_modules

smaller because you are using all these folders! It's just not always in the most direct way.

+1


source







All Articles