Skip to content

Instantly share code, notes, and snippets.

@ytxmobile98
Last active August 3, 2019 16:29
Show Gist options
  • Select an option

  • Save ytxmobile98/3981f093051206b6b75974537a9e0fdf to your computer and use it in GitHub Desktop.

Select an option

Save ytxmobile98/3981f093051206b6b75974537a9e0fdf to your computer and use it in GitHub Desktop.
JSX & LESS compile
echo "Usage: sh jsx-compile.sh [extension [outputDir [watchDir]]]\n"
echo "NOTE: If you have not yet initialized the jsx compile environment, please run the following commands first:"
echo "npm init -y"
echo "npm install --save-dev @babel/cli @babel/preset-react"
echo "See: https://reactjs.org/docs/add-react-to-a-website.html"
ext=".jsx"
outputDir="."
watchDir="."
if [ -n "$1" ]
then
ext="$1"
fi
if [ -n "$2" ]
then
outputDir="$2"
fi
if [ -n "$3" ]
then
watchDir="$3"
fi
echo "\nFile extension: $ext"
echo "Output directory: $outputDir"
echo "Watch directory: $watchDir"
read -p "Continue? (y/n): " -r reply
# See: https://thoughtbot.com/blog/the-unix-shells-humble-if
if test $reply != "Y" && test $reply != "y"
then
echo "Abort."
exit
fi
echo "\nPress ^C to exit\n"
# For the anatomy of the line below, see:
# https://reactjs.org/docs/add-react-to-a-website.html
# https://babeljs.io/docs/en/babel-node
npx babel --presets @babel/preset-react --watch "$watchDir" --out-dir "$outputDir" --extensions "$ext"
lessDir="./css-less"
cssDir="./css"
mainFile="index.less"
rootPath="./"
if [ -n "$1" ]
then
lessDir="$1"
fi
if [ -n "$2" ]
then
cssDir="$2"
fi
if [ -n "$3" ]
then
mainFile="$3"
fi
if [ -n "$4" ]
then
rootPath="$4"
fi
echo "Usage: sh less-compile.sh [lessDir [cssDir [mainFile [rootPath]]]]\n"
echo "LESS directiory: $lessDir"
echo "CSS directory: $cssDir"
echo "Main file: $mainFile"
read -p "Continue? (y/n): " -r reply
# See: https://thoughtbot.com/blog/the-unix-shells-humble-if
if test $reply != "Y" && test $reply != "y"
then
echo "Abort."
exit
fi
npx less-watch-compiler "$lessDir" "$cssDir" --main-file "$mainFile" --less-args rootpath="$rootPath",rewrite-urls=local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment