Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
881 views
in Technique[技术] by (71.8m points)

node.js - Compacting node_modules for client-side deployment

I'm implementing a client-side application in JavaScript using Node.js. Because I will be deploying the software on many machines, I would like to minimize the size of the package I distribute. In particular, I would like to remove any unnecessary files from node_modules.

For starters this means deduping and pruning the dependency tree, which npm can do for me. But I'd also like to remove all the package.json files and (especially) any other files that are not needed for deployment. In many of the packages I am using there are tons of tests, multiple versions of files (minified, browserified, etc.) and the like. I just need the JavaScript files that are actually used by the running app. Otherwise I'll be distributing a few 100Kb of files that aren't actually used.

I know about node-browserify but my app will be running in a CommonJS environment, not a browser, so I'd like to keep the modules separate and load them with require.

I'm thinking about writing a Grunt plugin that walks the dependency tree using required, pulls out the JavaScript files needed at runtime and writes them to a tree structure so they can be loaded using require (just loading the modules directly without needing a package.json). But I'd like to make sure no one has done this for me before I tackle it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

grun-package-minifier is not found ( This is not an actual answer. I wanted to commet in above answer but I do not have sufficient reputation yet :( ).

npm install grunt-package-minifier --save-dev Password: npm WARN package.json [email protected] No repository field. npm WARN package.json [email protected] No README data npm ERR! 404 404 Not Found: grunt-package-minifier npm ERR! 404 npm ERR! 404 'grunt-package-minifier' is not in the npm registry.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...