Last active
April 25, 2022 05:34
-
-
Save dethi/417f45e8d3be22e35d48087d551b1b6f to your computer and use it in GitHub Desktop.
create-react-app: find files not used in the app bundle, i.e. unused source code
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
#!/bin/bash | |
# Launch inside a create-react-app project after building the production build. | |
# Require `jq`. | |
diff \ | |
<(find src -type f \( -name '*.js' -o -name '*.jsx' -o -name '*.css' \) | sort) \ | |
<(cat build/**/*.map | jq --raw-output '.sources | join("\n")' \ | |
| grep -v '\.\./' | grep -E '\.(js|jsx|css)$' \ | |
| sed "s#^#src/#" | 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
Make sure that the
GENERATE_SOURCEMAP
env var is true