Skip to content

Instantly share code, notes, and snippets.

@cdaringe
Created June 29, 2015 01:25
Show Gist options
  • Save cdaringe/9876a24d71872ca45e0a to your computer and use it in GitHub Desktop.
Save cdaringe/9876a24d71872ca45e0a to your computer and use it in GitHub Desktop.
grunt npm dedupe
var spawnSync = require('spawn-sync');
var NODE_ENV = process.env.NODE_ENV;
var production = (NODE_ENV === 'production');
/**
* `npm dedupe` in cwd
* @return {undefined}
*/
var dedupe = function() {
var result;
result = spawnSync('npm', ['dedupe']); // 3rd arg, {cwd: ...}
process.stdout.write(result.stdout);
process.stderr.write(result.stderr);
if (result.status !== 0) {
process.exit(result.status);
}
};
module.exports = function(grunt) {
grunt.registerTask('dedupe', 'dedupe', function() {
if (!development) {
dedupe();
} else {
console.warn("notice: your browser dir will not be `npm dedupe`d in modes !== 'production'");
}
});
};
@cdaringe
Copy link
Author

use before browserifying or webpacking prd code, pre npm3.0 (which promises ultra de-duping greatness!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment