Consolidation of node_modules for client-side deployment

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.

+6
npm gruntjs browserify
source share
2 answers

FWIW: grunt-package-minifier . My use case is a bit unusual as we are developing a cross-browser extension infrastructure . As Browserify and unlike standard NodeJS deployments, we want to minimize the size of our distribution, including any CommonJS modules. But unlike Browserify we support CommonJS, so we can save the structure of the module, and not concatenate everything into one large file.

Essentially I deactivate all package.json , README, test files, etc. from node_modules , but I save essential JavaScript files in a structure that can be used by the CommonJS module loader.

+2
source share

grun-package- minifier not found (this is not a real answer. I wanted to link in the answer above, but I don't have enough reputation yet :().

npm install grunt-package- minifier --save-dev Password: npm WARN package.json zigbee_gateway_js@0.0.0 No repository field. npm WARN package.json zigbee_gateway_js@0.0.0 No data README npm ERR! 404 404 Not found: grunt-package- minifier npm ERR! 404 npm ERR! 404 'grunt-package-minifier' is not in the npm registry.

+2
source share

All Articles