Skip to content

Instantly share code, notes, and snippets.

@sungwoncho
Last active November 11, 2022 21:50
Show Gist options
  • Save sungwoncho/9d3301d41a54c4643b85690e1266d373 to your computer and use it in GitHub Desktop.
Save sungwoncho/9d3301d41a54c4643b85690e1266d373 to your computer and use it in GitHub Desktop.
Clean up previous build after a webpack build. Used in production at https://remotebase.io
# Store the filenames of previous build
PREVIOUS_BUILD=(./static/dist/*)
# ...
# build using webpack
# ...
# after the build
regex="([a-zA-Z_0-9]+)-([0-9a-z]+)\.(.*)"
for file in "${PREVIOUS_BUILD[@]}"
do
if [[ $file =~ $regex ]]
then
filename="${BASH_REMATCH[1]}"
hash="${BASH_REMATCH[2]}"
ext="${BASH_REMATCH[3]}"
if test -n "$(find ./static/dist -name "${filename}-[0-9a-z]*\.${ext}" ! -name "${filename}-${hash}*")"
then
# A newly generated file exists. Remove the old file.
rm "${file}"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment