Skip to content

Instantly share code, notes, and snippets.

@molotovbliss
Created September 20, 2017 10:41
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save molotovbliss/dbbcbcd0b2bb8581bbd190c40e3539dc to your computer and use it in GitHub Desktop.
Magento 2.x .less parser switch from PHP lessc to a C++ based for faster compile times.

PURPOSE:

  • .less parser switch from PHP lessc to a C++ implemenation (or Node.Js)

INSTRUCTIONS:

change directory into the root of your Magento 2 installation select LESS C++ (recommended!) or use alternative of Node.Js Lessc, which is most likely already included in with your Magento 2 install.

Author:


Less in C++

C++ implementation of lessc parser (MUCH FASTER!)

    wget https://github.com/BramvdKroef/clessc/archive/master.zip; unzip master.zip; cd ./clessc-master/; 
    ./autogen.sh; ./configure; make; make install; 

Check for compiled clessc compiled binary

clessc -h should now display an output


NODEJS LESSC ALTERNATIVE OPTION.

Node JS alternative (faster than the PHP version but, bleh node.js!)

    npm install grunt-contrib-less --save-dev; mv vendor/bin/lessc vendor/bin/lessc.php; 
    ln -nsT ../../node_modules/grunt-contrib-less/node_modules/.bin/lessc vendor/bin/lessc; chmod +x vendor/bin/lessc;

CONFIGURE MAGENTO 2 TO USE NEW PARSER INSTEAD ON SERVER GENERATION

Now simply mv the existing PHP lessc compiler to lessc.php and symlink
the C++ clessc or Node.JS lessc bin executables. whereis clessc for path

    mv vendor/bin/lessc vendor/bin/lessc.php; 
    ln -nsT ../../node_modules/grunt-contrib-less/node_modules/.bin/lessc vendor/bin/lessc; chmod +x vendor/bin/lessc;

BONUS

Simple bash script to check CWD is Magento 2 root folder

   if [ ! -f "bin/magento" ]; then
   echo "Magento directory not found, are you in the Magento 2 root folder?"
   exit 1;
   fi

EVEN MORE BONUS!

Someone else has already packaged up the NodeJs lessc switch as a M2 module:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment