Learn how you can Unlock Limitless Customer Lifetime Value with CleverTap’s All-in-One Customer Engagement Platform.
At CleverTap, we’ve recently started using LESS for dynamic CSS. While it has it’s upsides, the biggest downside was that most of our developers couldn’t use the hot deploy feature for their local deployments.
After an hour or so, we came up with a neat solution.
There are two parts to this:
Both parts above utilize a bash script (since everybody here at CleverTap uses a Mac for development, it’s cool).
Copy the following script and save it as /Users/username/bin/lessc-idea:
#!/bin/bash
exploded_artifact_path=/Users/jude/developer/CleverTap/out/artifacts/Dashboard_war_exploded
less=/usr/local/bin/lessc
function update {
target=`echo $1 | sed s/web\\// | sed s/.less/.css/`
echo "Generating $exploded_artifact_path/$target"
$less $1 $exploded_artifact_path/$target
}
function all {
find $exploded_artifact_path -name *.less | while read path; do
output=`echo $path | sed s/.less/.css/`
echo "Generating $output"
$less $path $output
done
}
$1 $2
If the code formatting looks messed up, you may view the code here, on GitHub
Note: You will need to update the variable exploded_artifact_path in the script above.
Make it executable:
$ chmod +x /Users/username/bin/lessc-idea
Now, open up your run configuration, and scroll all the way to the bottom (where it says Make, followed by Build artifact …). Hit the “+” button, and select “Run External Tool”.
Hit the “+” button to add a new External Tool, and configure it as follows:
Ensure that the build order in your run configuration is as follows:
Once this is done, your LESS files should be automatically generated when you deploy your web app. Go ahead and give it a shot.
Go to Preferences, and navigate to File Watchers under Tools (left menu). Hit the “+” button and select “Less”.
Configure your new watcher as shown in the screenshot below:
Before your hit the OK button, a few things to do:
You’re all set. Hit OK, then Apply, and OK.
Test drive your new setup. The moment you change a LESS file, it’ll get re-compiled into the corresponding CSS file within the corresponding directory in the artifact output, and you’ll be able to see the changes immediately.