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

2 Answers 2

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.

1
  • This is interesting, I haven't seen this approach before.
    – Kevin
    Dec 22, 2016 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

2
  • It returns: Registry returned 404 for GET on registry.npmjs.org/lessc It should be npm install -g less
    – Lenin Meza
    Dec 22, 2016 at 16:04
  • Sorry typo. Corrected
    – Kevin
    Dec 22, 2016 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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