-
Webseiten Hosting/Server Referenzen Kontakt/Impressum

How to compile LESS files to CSS with PHP, optionally in Eclipse

<< Back to overview / Zurück zur Übersicht

LESS is a great way to simplify the construction of CSS files.
But with the standard tools the LESS file is parsed at every access.
For performance reasons it would be better to have the option to compile the LESS files to CSS files.
To do this, lessphp can be used:
lesscompile.php:
<?php
if(!$GLOBALS['argv'][1]) die('Please give me an input filename');

if(strtolower(substr($GLOBALS['argv'][1],-5))==='.less')
{
include_once('lessc.inc.php');
try {
lessc::ccompile($GLOBALS['argv'][1],str_replace('.less','.css',$GLOBALS['argv'][1]));
} catch (exception $ex) {
exit('lessc fatal error:'.$ex->getMessage());
}
echo "OK, file compiled.";
}
else
{
echo "This is not a .less file";
}
?>
Then you can compile a LESS file on the command line with:
php lesscompile.php path/file.less
where path/file.less is your .less file. It will result in a compiled CSS file with the same name.
Option: Make a "Compile" Button in Eclipse.

Click the "Arrow down"-Button besides the green "Play"-Button (the one with a small red suitcase).
Then "External Tools Configuration".
Right-click on "Program", select "New".
Location: Full path to your php.exe
Arguments: fullpath/lesscompile.php ${resource_loc}
Save the config.
After that you can select the compile-action from the drop-down-Button list. The currently opened LESS file will be compiled.
Or you can click the green play-button itself to execute the last action.
Without any warranty - use this information at your own risk.
Created at 2011-11-09
Tags: less css compile php eclipse



Seite zuletzt geändert am: 23.01.2019