Last active
September 5, 2018 09:01
-
-
Save mr21/4e0c33fb4e385b3fc884463216a23fce to your computer and use it in GitHub Desktop.
This shell script prints all the CSS/JS in the same index.html file
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/sh | |
# usage: ./build-prod.sh < index.html > index-prod.html | |
cssURLs=() | |
jsURLs=() | |
cssReg="<link.*['\"](.*\.css)['\"].*>" | |
jsReg="<script.*['\"](.*\.js)['\"].*></script>" | |
while read line | |
do | |
if [[ $line =~ $cssReg ]]; then | |
cssURLs+=(${BASH_REMATCH[1]}) | |
elif [[ $line =~ $jsReg ]]; then | |
jsURLs+=(${BASH_REMATCH[1]}) | |
elif [[ $line = "</head>" ]]; then | |
echo "<style>" | |
cat ${cssURLs[@]} | |
echo "</style>" | |
echo "</head>" | |
elif [[ $line = "</body>" ]]; then | |
echo "<script>" | |
cat ${jsURLs[@]} | |
echo "</script>" | |
echo "</body>" | |
else | |
echo $line | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment