Last active
August 3, 2019 16:29
-
-
Save ytxmobile98/3981f093051206b6b75974537a9e0fdf to your computer and use it in GitHub Desktop.
JSX & LESS compile
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
| *.txt |
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
| 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" |
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
| 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