Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.