Using LESS in an add-on?

I’ve scoured the developer docs, the ConcreteCMS source code and the forums for an answer but can’t seem to find it. So I’m reaching out, hoping to know if this is possible -

I am looking to include LESS files with an add-on (not a theme). I’ve seen how Concrete can handle that in a theme environment (with the getStylesheet function). But can’t see for the life of me how to do this in an add-on.

Is it possible?

I should clarify, either LESS or SASS is fine in my case.

The LESS compiler is still there and is considerably more efficient than compiling SASS with php. The class is Less_Parser and is used, amongst other places, by concrete/src/StyleCustomizer/Stylesheet.php and is also still used by themes including Elemental concrete/themes/elemental/elements/header_top.php <?php echo $html->css($view->getStylesheet('main.less')) ?>

In an addon (or theme) you could

  1. Compile LESS as part of the install process
  2. Serve cached CSS from LESS or compile on demand (similar to the theme getStylesheet() )
  3. Compile when saving an edit dialogue

All strategies can work, depends on whether you need to inject any dynamic values.

1 Like

Thanks for the feedback, John. Very helpful!
It seems like I’ll have to build some of the functionality, as it’s not quite as plug n play as the theme support for LESS/SASS.
I’m thinking of building it when saving the block and caching the css for faster performance.