Skip to content

Instantly share code, notes, and snippets.

@turadg
Created December 8, 2017 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turadg/16399a5cef8c8c9905dad0d7e8dda3c0 to your computer and use it in GitHub Desktop.
Save turadg/16399a5cef8c8c9905dad0d7e8dda3c0 to your computer and use it in GitHub Desktop.
Find in webpack builds modules that are never imported
#!/bin/bash
echo "Testing prod build for modules in src that aren't ever imported."
echo
echo "NOTE: Any dev-only imports will appear to be unused."
USED_LIST_PATH=usedModules.txt
STATS_PATH=public/assets/stats.json
if [ ! -e $USED_LIST_PATH ]; then
echo Building module stats
yarn build-prod
jq .modules[].name $STATS_PATH |tr -d '"' > $USED_LIST_PATH
fi
SELECT_RE=".*\.(jsx?|s?css)$"
src_modules=`find -E src -regex $SELECT_RE | grep -v -E "__tests__|mocks|dev|fixtures|mixins"`
echo "These modules are never built into Webpack:"
for module in $src_modules ; do
grep --quiet $module usedModules.txt
if [[ $? != 0 ]]; then
echo $module
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment