I am using a client application in JavaScript using Node.js. Since I will deploy software on many machines, I would like to minimize the size of the redistributable package. In particular, I would like to remove any unnecessary files from node_modules.
For starters, this means deduplicating and trimming the dependency tree, which npm can do for me. But I would also like to delete all the package.json files and (especially) any other files that are not needed for deployment. In many packages that I use, there are many tests, several versions of files (minified, browser, etc.) and the like. I just need the JavaScript files that are actually used by the running application. Otherwise, I will distribute several 100Kb files that are not actually used.
I know about node-browserify , but my application will work in the CommonJS environment, and not in the browser, so I would like to keep the modules separated and load them using require .
I am thinking of writing a Grunt plugin that traverses the dependency tree using required , pulls out the JavaScript files needed at runtime and writes them to the tree structure, so they can be loaded using require (just loading the modules directly, without requiring package.json ) . But I would like to make sure that no one did this for me before doing this.
Matthew gertner
source share