Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mr21
Last active September 5, 2018 09:01
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 mr21/4e0c33fb4e385b3fc884463216a23fce to your computer and use it in GitHub Desktop.
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
#!/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