In projects where there is the package.json
file, in addition to the uninstall already mentioned in the previous response, you can use the command:
node prune
Simply edit the file package.json
so that it contains only the dependencies that you use and run the command it will delete all packages that are in node_modules
and that you do not reference in package.json
. >
It is also recommended that in package.json
you put in the postinstall script the command npm prune
so that after a version update for example, the most unused packages are removed. >
Example of package.json
with script of postinstall :
{
"name": "teste",
"version": "1.0.0",
"description": "Teste",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "npm prune"
},
"author": "bigous",
"license": "ISC",
"dependencies": {
"luaparse": "^0.2.1"
}
}
In this example, any package except [email protected]
will be removed from node_modules
with the command node prune
or after a npm install
with no more parameters.