Skip to content

Instantly share code, notes, and snippets.

@Naahuel
Forked from dethi/unused-files.sh
Last active July 17, 2018 17:21
Show Gist options
  • Save Naahuel/a0b45b9b8367eeb6ef5adfde6b156a69 to your computer and use it in GitHub Desktop.
Save Naahuel/a0b45b9b8367eeb6ef5adfde6b156a69 to your computer and use it in GitHub Desktop.
Find files not used in the app bundle, i.e. unused source code
#!/bin/bash
# Launch inside a react project after building the production build with webpack
# Require `jq`.
diff \
<(find src -type f \( -name '*.js' -o -name '*.jsx' -o -name '*.scss' \) | sort) \
<(cat dist/**/*.map | jq --raw-output '.sources | join("\n")' \
| grep -v '\.\./' | grep -E '\.(js|jsx|scss)$' \
| sed "s~^webpack:///\./~~" -r | sort | uniq) \
| grep '< ' | sed "s#^< ##" | grep -v 'spec'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment