Created
November 8, 2015 15:38
-
-
Save etiktin/455b09cb426477a35cc3 to your computer and use it in GitHub Desktop.
Using npm API to remove dev dependencies from your node_modules folder (equivalent of `npm prune --production`)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var npm = require('npm'); | |
var cb = funtion (error) { | |
if (error) { | |
console.log('Failed to remove devDependencies'); | |
} else { | |
console.log('devDependencies removed from node_modules'); | |
} | |
}; | |
// Before calling a command we need to setup it's configuration | |
npm.load({ | |
production: true, // Will make prune remove devDependencies | |
prefix: PATH_TO_NODE_MODULES_PARENT // Optional. If not provided, remove node_modules from the current app | |
}, | |
function (error) { | |
if (error) { | |
cb(error); | |
return; | |
} | |
// The configuration is ready so we call the prune command | |
npm.commands.prune(cb); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment