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' |
Changing the cat
command on line 8 to cat build/**/**/*.map
worked.
since you are already using find. a better version of the cat command would be
find build -iname '*.map' -exec cat {} \;
so
- <(cat build/**/*.map | jq --raw-output '.sources | join("\n")' \
+ <(find build -iname '*.map' -exec cat {} \; | jq --raw-output '.sources | join("\n")' \
Make sure that the GENERATE_SOURCEMAP
env var is true
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cat: 'build/**/*.map': No such file or directory