DEV Community

Discussion on: Remove unused npm modules in less than 30 seconds!

Collapse
guhkun13 profile image
name cannot be blank • Edited

so i created this script to remove ALL UNUSED deps, (works in unix):

#!/bin/bash
file='unused-deps.txt'
echo "list all unused deps"
npx depcheck > $file
n=1
while read line; do
dep=$( echo "$line" | cut -c 3- )
echo "uninstall : $dep"
npm uninstall "$dep"
n=$((n+1))
done < $file

  • save the script as whatever you want, ex: removeUnusedDeps.sh
  • then bash removeUnusedDeps.sh in your terminal