How would I go about cleaning the node_modules folder when prepping my code for deployment.
I am making an app using node-webkit and would prefer to include the least amount of files possible when bundling the final version of the app as the unzip process takes some time.
I've looked at npm dedupe
and use npm install --production
to get rid of duplicates and fetch only production files, however I am still left with Readme
files, benchmarks
, tests
and build
files which I don't need.
What I would like to end up with for each module in the node_modules
folder is a LICENSE
file if it exists, the package.json
and anything else that I need for the module to run, but nothing more.
The question: How to automatically clean a node_modules directory for a SCM commit was heading somewhat in the same direction, but it is talking about committing so not really what I am looking for.
The question: NPM clean modules again was somewhat along the same lines as mine, but not quite fully there.
This answer helps as it is more efficient version for dedupe
for bundling the final app.
Update
I tried the custom module linked from here but it didn't seem to work correctly, even after some fiddling about.
With all that said, I haven't quite found the right answer yet.
Here's an example of what I am looking for.
In my project I currently have two dependencies: socket.io
and socket.io-client
.
Together they make up 15 MB with 550 files in 110 folders.
Manually cleaning readme
, makefile
, VC++
build files such as .pdb
and .obj
and other unnecessary files I was able to shrink it down to 2.74 MB with 265 files in 73 folders.
This is with just two modules.
I would like to find out if there is a way to do this automatically, preferably with npm
.
Well cleaning the
node_modules
for the deployment for a webkit application, its kind of difficult, because of the modules insidenode_modules
directory are installed with or without test files other misc files and so, if the owner of the module, has declared an.npmignore
file with dir/files such astests
orexamples
those will be excluded from packaging process when the owner publishes his module, but it will exist in the repository (git) as normal.Exclude test code in npm package?
the above is left in module owners hands, if he/she "forgets" to make one, then package will contain pretty much everything.
Note that since you don't use the
development
package ofsocket.io
orsocket.io-client
it doesn't mean you have tonpm install socket.io --save-dev
, a simplenpm install socket.io -V
would install the production package as it was uploaded by its owner.A possible workaround would be to make a
grunt
task, to clean your entirenode_modules
as you would like it to be.a couple of rules would be
test
ortests
directory or*test*.js
filesbuild
directories (not sure about it might contain some binaries sometimes that are necessary)history.md
GruntJS
Hope i helped somehow, also take a look at Tilemill and how they deploy their application.