有没有办法自动生成bundledDependencies列表?

我有一个应用程序,我正在部署到Nodejitsu。 最近,他们遭受了npm的问题,导致我的应用程序在我尝试(并失败)重新启动后几个小时脱机,因为它的依赖关系无法安装。 有人告诉我,将来可以通过将我的所有依赖列表作为bundledDependencies在package.json中,从而导致依赖与应用程序的其余部分一起上传。 这意味着我需要我的package.json看起来像这样:

 "dependencies": { "express": "2.5.8", "mongoose": "2.5.9", "stylus": "0.24.0" }, "bundledDependencies": [ "express", "mongoose", "stylus" ] 

现在,在DRY的理由,这是没有吸引力。 但更糟糕的是维护:每次添加或删除依赖项时,我都必须在两个地方进行更改。 有没有一个命令我可以用来同步bundledDependencies dependenciesdependencies

如何执行一个grunt.js任务来做到这一点? 这工作:

 module.exports = function(grunt) { grunt.registerTask('bundle', 'A task that bundles all dependencies.', function () { // "package" is a reserved word so it's abbreviated to "pkg" var pkg = grunt.file.readJSON('./package.json'); // set the bundled dependencies to the keys of the dependencies property pkg.bundledDependencies = Object.keys(pkg.dependencies); // write back to package.json and indent with two spaces grunt.file.write('./package.json', JSON.stringify(pkg, undefined, ' ')); }); }; 

把它放在你的项目的根目录下,名为grunt.js 。 要安装grunt,使用npm: npm install -g grunt 。 然后通过执行grunt bundlegrunt bundle

一位评论员提到了一个可能有用的npm模块: https : //www.npmjs.com/package/grunt-bundled-dependencies (我还没有尝试过)。