Last active
November 11, 2022 21:50
-
-
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
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
# 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