Created
March 2, 2017 08:51
-
-
Save tscanlin/bf147af42c15e6f2debc1cf38c90ac0c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Use preact | |
# Switch a react project to using preact if its isn't using it already. | |
# | |
# EX: grep -rl "preact-compat" ./node_modules/react-scripts/config/ | |
# EX: find ./node_modules/react-scripts/config/*.config.* -type f -exec sed -i "s/alias: {/alias: {\n\t\t\t\'react\': \'preact-compat\',\n\t\t\t\'react-dom\': \'preact-compat\',/gi" {} \; | |
searchString=${1:-preact-compat} | |
filePattern=${2:-./node_modules/react-scripts/config/} | |
replaceString="alias: {" | |
newString="alias: {\n\t\t\t\'react\': \'preact-compat\',\n\t\t\t\'react-dom\': \'preact-compat\'," | |
SEARCH="$(grep -rl "$searchString" $filePattern)" | |
echo "${SEARCH}" | |
if [ ! "${SEARCH}" ] | |
then | |
echo "preact was not detected, adding it as a webpack config alias..." | |
REPLACE="$(find $filePattern -type f -exec sed -i "s/$replaceString/$newString/gi" {} \;)" | |
echo "${REPLACE}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment