1

How can i preprocessor or compile at runtime the LESS files in the latest version of Drupal 8?

I am using the LESS starterkit theme of Bootstrap. The Less CSS Preprocessor is currently not ported to Drupal 8.

The next two guides says that i need NodeJS and the less package to compile it, but it is not at the runtime of Drupal:

lessc less/style.less > css/style.css
  1. Creating a Bootstrap subtheme for Drupal 8
  2. How to build your Drupal 8 theme using Bootstrap & Less
3

If you don't want to wait for the port of the Less CSS Preprocessor module to run the less compiler at run time, you can execute the command line tool from settings.php

exec('lessc themes/mytheme/less/style.less themes/mytheme/css/style.css > /tmp/less-debug 2>&1');

This is only for development, remove this from the production settings.php.

  • This is interesting, I haven't seen this approach before. – Kevin Dec 22 '16 at 10:59
2

lessc is referring to this npm package:

http://lesscss.org/

You could either install it globally, or have it at the theme level with your own package.json and execute it from the theme directory.

To install globally with npm:

npm install -g less

lessc is then a command available at your command line and then your compile command will work.

See: http://lesscss.org/#using-less-installation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.