Hi, when can D8 version be expected? I would kill for this right now but I don't have the time to rewrite the code myself :(

Drupal 8 port tracker: https://www.drupal.org/node/2619554

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

This is my quick fix which uses inline css instead of creating new files and it's parsing files on every request. It uses https://github.com/oyejorge/less.php/releases parser in module's "assets/vendor/less.php/Less" directory.

/**
 * Implements hook_css_alter().
 */
function mymodule_css_alter(&$css) {
  \Drupal::moduleHandler()->loadInclude('mymodule', 'php', 'assets/vendor/less.php/Less');
  $base_url = url('', array('absolute' => TRUE));

  foreach ($css AS &$style) {
    if ($style['type'] == 'file' && substr($style['basename'], -5) == '.less') {
      $dir = substr($style['data'], 0, strlen($style['basename']) * -1);
      $less = new \Less_Parser();
      $less->parseFile($style['data'], $base_url . $dir);
      $style['data'] = $less->getCss();
      $style['type'] = 'inline';
    }
  }
}
corey.aufang’s picture

So there is a slight hold up on this.

I had first looked at porting to D8 around a year and a half ago, but at the time decided to postpone since D8 specs seemed to be in rapid flux.

Since then, D8 now requires PHP 5.4 which my Ubuntu 12.04 laptop does not support.

So as soon as I figure a way to get a reasonable development environment going, a D8 port will be started.

I've been looking at a Lenovo w540 and possibly switching back to Windows, which would bring me up to 5.4-5.5.

Anonymous’s picture

corey.aufang’s picture

Yeah, I can't use that method because there are still some of my clients that are on Drupal 6 and don't want to upgrade.

I've been looking at the phpbrew method to be able to switch to any php version that I need at that moment.

Undrium’s picture

Heyas, what's the status on this one? Our team is dire to use this module to the 8th. :)

Niels de Ruijter’s picture

Because #1 didnt seem to work for me, I made this very primitive implementation. No idea if this is the correct way in Drupal 8, so correct me if Im wrong.

/**
 * Implements hook_css_alter().
 * @todo Compare mtime for caching.
 */
function mymodule_css_alter(&$css) {
  if (!class_exists('Less_Parser')) {
    require_once DRUPAL_ROOT.'/assets/vendor/less.php/lib/Less/Autoloader.php';
    Less_Autoloader::register();
  }
  global $base_url;

  foreach ($css as &$style) {
    if ($style['type'] == 'file' && substr($style['basename'], -5) == '.less') {
      $dir = substr($style['data'], 0, strlen($style['basename']) * -1);
      $less = new Less_Parser();
      $less->parseFile($style['data'], $base_url . $dir);
      $data = $less->getCss();
      $replacement = substr($style['basename'], -9) == '.css.less' ? '' : '.css';
      $style['basename'] = substr_replace($style['basename'], $replacement, -5);
      $directory_path = 'public://mymodule';

      if (!is_dir($directory_path)) {
        file_prepare_directory($directory_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
      }
      $file_uri = file_unmanaged_save_data($data, "{$directory_path}/{$style['basename']}", FILE_EXISTS_REPLACE);

      if ($file_uri) {
        $style['data'] = file_create_url($file_uri);
      } 
     else {
        // Put the css inline if we fail to create a file.
        $style['data'] = $data;
        $style['type'] = 'inline';
      }
    }
  }
}
Martijn Houtman’s picture

I am reading about an effort for Assetic being integrated into D8 core. Maybe a collaboration would be a good idea.

https://www.drupal.org/node/1751602
https://www.drupal.org/node/352951

joelpittet’s picture

@Martijn Houtman it was removed unfortunately #2356845: Remove the assetic library.

Not enough people got behind flushing out how to meld it with D8. Though there are a bunch of issues getting through now that pave for maybe an easier integration later if someone wants to pick it up again.

#2377397: Themes should use libraries, not individual stylesheets
#2378095: Convert all remaining attached individual CSS/JS assets to attached asset libraries
#2382557: Change JS settings into a separate asset type

corey.aufang’s picture

Version: 7.x-3.x-dev » 7.x-4.x-dev

Ok, so I had been holding off on a D8 version because D8 was still in Alpha, or so I had convinced myself.

Part of my original hesitation was lack of experience with OOP for PHP, something that I have recently become much more familiar with.

Some of this is now reflected in the latest less 7.x-4.x-dev.

I would like to carry over some of what I've done in 7.x-4.x to 8.x-4.x, but especially finish and release 7.x-4.0 before I get too in-depth with 8.x-4.x.

So if any of you have some time, please review 7.x-4.x and let me know what you think.

If there are any WTFs, code or otherwise, or anything that you feel could be done better, please let me know.

corey.aufang’s picture

Status: Active » Needs work
Undrium’s picture

Just want to mention that as of beta version 4, the ability to inject "inline" css and JS is removed. The two temporary solutions mentioned in this thread are therefor obsolete, however the latter can be modified to work if you just remove the type declaration of "inline".

corey.aufang’s picture

Unless any major issues crop up in the 7.x-4.x branch in the next few days, 7.x-4.0 will be releasing soon.

Work on a D8 version will begin immediately after.

corey.aufang’s picture

Version: 7.x-4.x-dev » 8.x-1.x-dev

Work has started on the D8 version.

I'm not going to list the dev release on the project page until I have it minimally working.

Anonymous’s picture

Hi. I have updated my ongoing project to the latest D8 alpha and then HEAD and as #11 mentioned the support for inline styles was dropped so I had to update my solution from #1 to this:

function somename_css_alter(&$css) {
  \Drupal::moduleHandler()->loadInclude('somename', 'php', 'assets/vendor/less.php/Less');// <---- change this to your location
  $base_url = \Drupal::url('<front>', array(), array('absolute' => TRUE));
  $public_path = \Drupal::service('stream_wrapper.public')->getDirectoryPath();
  foreach ($css AS &$style) {
    if ($style['type'] == 'file' && substr($style['basename'], -5) == '.less') {
      $filepath = $public_path . '/less/' . str_replace('/', '--', substr($style['data'], 0, -5));
      // If the file does not exist, process the original LESS file and output
      // the data into the temporary file.
      if (!file_exists($filepath)) {
        // Make sure the 'less' subdirectory exists.
        \Drupal::service('file_system')->mkDir($public_path . '/less');
        // Parse the original LESS file.
        $dir = substr($style['data'], 0, strlen($style['basename']) * -1);
        $less = new \Less_Parser();
        $less->parseFile($style['data'], $base_url . $dir);
        file_put_contents($filepath, $less->getCss(), FILE_USE_INCLUDE_PATH);
      }
      // Point to the parsed file.
      $style['data'] = $filepath;
    }
  }
}
Anonymous’s picture

My current version:

/**
 * Implements hook_css_alter().
 */
function modulename_css_alter(&$css) {
  \Drupal::moduleHandler()->loadInclude('modulename', 'php', 'assets/vendor/less.php/Less');
  $cache_id = \Drupal::state()->get('system.css_js_query_string');
  $base_url = \Drupal::url('<front>', [], ['absolute' => TRUE]);
  $public_path = \Drupal::service('stream_wrapper.public')->getDirectoryPath();
  foreach ($css AS &$style) {
    if ($style['type'] == 'file' && substr($style['basename'], -5) == '.less') {
      // Remove the '.less' extension.
      $file_name = substr($style['data'], 0, -5);
      // If there is '.css' extension left, remove it for hashing purposes.
      if (substr($file_name, -4) == '.css') {
        $file_name = substr($style['data'], 0, -4);
      }
      // Create full path to the new file.
      $file_path = $public_path . '/less/' . $cache_id . '/' . hash('md5', $file_name) . '.css';
      // If the file does not exist, process the original LESS file and output
      // the data into the temporary file.
      if (!file_exists($file_path)) {
        // Make sure the 'less' subdirectory exists.
        \Drupal::service('file_system')->mkDir($public_path . '/less');
        // Make sure the subdirectory for the current cache key exists.
        \Drupal::service('file_system')->mkDir($public_path . '/less/' . $cache_id);
        // Parse the original LESS file.
        $dir = substr($style['data'], 0, strlen($style['basename']) * -1);
        $less = new \Less_Parser();
        $less->parseFile($style['data'], $base_url . $dir);
        file_put_contents($file_path, $less->getCss(), FILE_USE_INCLUDE_PATH);
      }
      // Point to the parsed file.
      $style['data'] = $file_path;
    }
  }
}

/**
 * Implements hook_cache_flush().
 */
function modulename_cache_flush() {
  // Delete parsed LESS styles and cache directories.
  file_unmanaged_delete_recursive('public://less');
}
Anonymous’s picture

Updated


/**
 * Implements hook_css_alter().
 */
function modulename_css_alter(&$css, AttachedAssetsInterface $assets) {
  \Drupal::moduleHandler()->loadInclude('modulename', 'php', 'assets/vendor/less.php/Less');
  $cache_id = \Drupal::state()->get('system.css_js_query_string');
  $public_path = \Drupal::service('stream_wrapper.public')->getDirectoryPath();
  foreach ($css AS &$style) {
    if ($style['type'] == 'file' && substr($style['data'], -5) == '.less') {
      // Remove the '.less' extension.
      $file_name = substr($style['data'], 0, -5);
      // If there is '.css' extension left, remove it for hashing purposes.
      if (substr($file_name, -4) == '.css') {
        $file_name = substr($style['data'], 0, -4);
      }
      // Create full path to the new file.
      $file_path = $public_path . '/less/' . $cache_id . '/' . hash('md5', $file_name) . '.css';
      // If the file does not exist, process the original LESS file and output
      // the data into the temporary file.
      if (!file_exists($file_path)) {
        // Make sure the 'less' subdirectory exists.
        \Drupal::service('file_system')->mkDir($public_path . '/less');
        // Make sure the subdirectory for the current cache key exists.
        \Drupal::service('file_system')->mkDir($public_path . '/less/' . $cache_id);
        // Parse the original LESS file.
        $source_directory = explode('/', $style['data']);
        array_pop($source_directory);
        $source_directory = '/' . implode('/', $source_directory);
        $less = new \Less_Parser();
        $less->parseFile($style['data'], $source_directory);
        file_put_contents($file_path, $less->getCss(), FILE_USE_INCLUDE_PATH);
      }
      // Point to the parsed file.
      $style['data'] = $file_path;
    }
  }
}

/**
 * Implements hook_cache_flush().
 */
function modulename_cache_flush() {
  // Delete parsed LESS styles and cache directories.
  // Wrap this into condition to avoid dblog entries
  // for non-existing directory.
  $path = 'public://less';
  if (is_dir($path)) {
    file_unmanaged_delete_recursive($path);
  }
}

veleno’s picture

Hello ivanjaros, I'd like to implement your code in my custom theme, into the THEMENAME.theme file but I've not been able to make it work.
Could you please help me modifing your code so it will work if used into the theme?

Thank you for your time.

Anonymous’s picture

sachbearbeiter’s picture

Title: Version for Drupal 8 » Less CSS Preprocessor: Drupal 8 version
veleno’s picture

Thank you ivanjaros, but I've not been able to convert your shared code in a module or a template function.
I'm new to drupal 8 and to module creation.
Would you please be more clear?

Thank you

Anonymous’s picture

copy the code from .module, .info.yml and composer.json into a directory, run composer install. Gist has split the module into files where their name is the directory structure so it looks weird even if you download it.

veleno’s picture

FileSize
62.43 KB

Thanks again ivanjaros, I've been able to make it work.
I've uploaded the working version of the module in this post, I've put the less.php library inside the module directory.
It compiles Bootstrap 3 correctly now, I'm using it with the less sub-theme starterkit of the Bootstrap theme at https://www.drupal.org/project/bootstrap.

Hope the full Less CSS Preprocessor module could be released as soon as possible for Drupal 8
Regards

Frantsuzzz’s picture

Hello veleno. Added Developer Mode to the module store_less_css.
It may be useful.

Regards

SchnWalter’s picture

Assigned: Unassigned » SchnWalter

Hello all,
I have just cloned the module repository to https://gitlab.com/SchnWalter/drupal8-less and I will start working on having a basic module for Drupal 8 sometimes in the next weeks.

Regards,
Walter S.

SchnWalter’s picture

Quick question: "LESS engine" isn't really a proper term. Would it be OK if I replace the terminology to use "preprocessor" which is a more popular term? I know it will break the translations but it would be less confusing. I've never seen "engine" used to describe these kind of libraries.

SchnWalter’s picture

I've converted the "engines" to a LessEngine annotation plugin and I've added a settings form page that extends ConfigFormBase and right now I have a working module on my local machine, that is not committed onto the gitlab repo, I'll need to do some cleanup and refactoring before I push a simple working version onto that repo.

I've been working on supporting the devel and watch modes and I've finally found a solution by using an approach similar to how the image styles work. Basically we don't save the files on disk when devel mode is enabled, but we stream them directly to the browser. I've chosen this approach because I could not find a clean way of implementing the functionality without introducing some changes into Drupal core, and I think that this approach is perfectly suitable since Drupal developers are already familiar to this pattern.

And I think that we should not add hook_less_variables_SYSTEM_NAME_alter and hook_less_paths_SYSTEM_NAME_alter in the D8 version since the values for those hooks are not namespaced and there is no to only alter variables declared by a single module and those are very edge cases. We should simplify things. Maybe we can add those back later after a fist beta version has been released.

SchnWalter’s picture

I've pushed a working Drupal 8 port onto: https://gitlab.com/SchnWalter/drupal8-less

There are some missing features or issues:

* Watch mode is not finished yet. We'll need to update the less_css_cache_files state to include more information.
* In 7.x-4.x a module/theme can define default variables and import directories inside .info files that are only available to the less files from that module/theme. I'm not sure if you agree, but I believe that feature ads a bit of confusion and I don't see any relevant use cases.
* There are not LESS settings on the theme settings page.
* WYSIWYG .less files are not compiled.
* Autoprefixer has not been enabled, code is commented out. It only works with files and the current devel mode does not create files.
* Tests are missing, and the old tests have not been updated.
* Demo module has not been updated.
* README.md file has not been updated.

SchnWalter’s picture

Status: Needs work » Needs review
FileSize
131.37 KB
57.8 KB

Added patch and admin settings page screenshot.

LESS Settings page screenshot

corey.aufang’s picture

This is not based on a review of your code.
I just went over your notes and provided feedback to give an idea of the road ahead.

Engines
I used the term "engines" because you were choosing what library was being "under the hood".
The module supplants the preprocessor and then delegates the task to the selected library.
I was doing a bunch of "Libraries" hooks and integration and didn't want to have too much confusing terminology in the code, but for the radios label it should probably be "Less library:".
Also, since its a jump to D8, the libraries hooks and "engines" can be simplified somewhat without having to be backwards compatible.
There was a lot of backwards comatibility code in the libraries hooks to work with all the paths that the module support for legacy reasons.
With the lower chance of users doing the D7->D8 migration, dropping support to older libraries path locations should be pursued.
Devel Mode
Did something change drastically with the file system handling in D8?
Streaming the files seems like it will introduce significant lag time to page loads during when devel mode is enabled, even with cache headers for the browser.
Image styles work fine because you change their configuration for more infrequently than when adjusting CSS styles during theming.
D7 devel mode checked for changes in a file and its dependencies before recompliling, and all results were stored to disk to be loaded directly through the web server bypassing PHP.
Could you tell me the specific issues you had adapting the Devel Mode for D8?
Watch Mode
I was never completely happy with my functionality for this, and I actually rarely used it myself.
#2730749: Long-polling watch mode introduced the concept of long-polling instead of the rapid polling that I had implemented.
In short, you make a AJAX request to a PHP script that checks for changes, but keeps the connection open until changes are detected, or if execution time is about to be reached. The JS will reload the CSS if the PHP returns data, or restarts the AJAX if the connection is closed without result.
This is also know as Comet.
Hooks
I have no issues at first glance with dropping those hooks, but not under the pretext of adding them back later after some time.
Either we figure out how to make them function as D7 does, or we drop them.
.info
Default variables were implemented there with the intention that you could alter them in the theme settings.
Import directories, I think it was so that you could specify a "library" .less file that might not be located in the same module, but possibly a sibling module. Don't really remember specifically.
If I was doing it again, I would not use the .info file and only use hooks for providing these, so probably don't need to support in D8.
Theme settings form
This is a critical differene between compiling on dev machine vs. live website.
You can make changes to things like key color variables and those variables will then be used by the .less files when they are re-compiled, all directly from the theme settings page.
No FTP or other access required.
Autoprefixer
This functioning is a practical requirement.
Autoprefixer removes the need in most cases for Less libraries that handle things like box-shadow for all the different browsers.

The original reason for making this module 6+ years ago is that it was difficult to get the original Less compiler setup and running on a development machine and to have it integrated into your workflow without issues.

This is drastically easier now.

Additionally, since the .less file developed by one person using a specific version of the compiler, will be run by another person with a potentially different version and/or compiler, there is a chance that the file will not compile due to changes in supported language features.

So with the above I believe that the focus of the module needs to be narrowed.

I believe that its a bad idea to promote the module compiling any .less file that you have not made. Specifically, if you are developing a website and making a custom module/theme for the site, you can use the Less module to compile your .less files to CSS.

But, you should not use this module to compile .less files from contributed modules/themes/libraries, not should you as a module/theme developer intend for users to use this module to compile .less files that you provide in your module.
There are just too many issues that can arrise from what people assume the language supports, when the library is lagging behind feature wise, or the installed version of less.js is outdated.

The only thing that I see making this module more valuable than compiling in your local/dev copy is the theme settings form, because you can make changes to the styling without having to know much about CSS. It also means you can mess things up easily, but thats the case with most things.

Properly functioning sourcemaps also factors into this. They need to be working 100% as it is unreasonable today to not support them, since all major browsers to. There have been issues implementing it correctly since the derived output .css files do not live in the same directory as the source .less files, the pathing gets messed up.

Main items:

  1. Autoprefixer - I believe that this is a practical requirement in any CSS development, not just Less, and would be a critical mistake to not have functioning.
  2. Theme settings form - This is the major value that this module brings compared to any other method.

Everything is flexible. All feedback in welcome. Nothing is set in stone.

SchnWalter’s picture

Thanks for your feedback. I'll go over every point and provide an answer later this week.

About Devel Mode: There are some cache issues that I could not find a way to get around them and I wanted to quickly have a basic working module and this was the quickest and simplest workaround I could find. But yes, maybe we can also cache the file and just serve it via Drupal if we don't find a solution for the cache issue inside \Drupal\Core\Asset\AssetResolver::getCssAssets(). Maybe we could introduce an extra hook in D8 core to alter libraries. (Not this hook: https://www.drupal.org/node/2785815)

SchnWalter’s picture

Status: Needs review » Needs work
rphair’s picture

thanks @SchnWalter - I've installed the Gitlab version on Drupal 8.2.1, with Libraries module already installed & just oyejorge/less.php extracted into /sites/all/libraries/less.php/Less.php. I get the following message when visiting configuration page /admin/config/development/less:

Fatal error: Class 'lessc' not found in /.../modules/less/src/Plugin/LessEngine/LeafoLessphp.php on line 64

Have I left something out? If so please let me know & I will happily continue to test.

SchnWalter’s picture

I just updated the module and added the extra check required to prevent that issue.

rphair’s picture

dear @SchnWalter - thanks so much, now the module installs and I have it working with less/less.js - it's really nice to have this up & running in any form on Drupal 8.

I still can't make it work with oyejorge/less.php - the option is still greyed out after making sure Less.php is there at /sites/all/libraries/less/Less.php. However you installed this code to get the screenshot above with that option selectable, I would love to know.

I've tried clearing the cache, also tried putting the library in /libraries. I do have the Libraries module installed properly & I haven't downloaded the source code version by mistake.

rphair’s picture

p.s., the gitlab instructions also say to install the file at /sites/all/libraries/less.php/Less.php but I am not seeing it recognised there either.

SchnWalter’s picture

@rphair, I didn't update any documentation.

I'm using this composer command to install the oyejorge/less.php library.
composer require oyejorge/less.php ~1.7
Though, I'm not sure how one would deal with installing custom PHP libraries and exposing them to the Drupal autoloader without using Composer.

If you want to give composer a try, you should check this page: https://www.drupal.org/docs/develop/using-composer/using-composer-to-man...

rphair’s picture

yes, it's recognised after installing with composer (composer require oyejorge/less.php was enough for me). Thanks very much, I agree this way is better, though other libraries I have worked with so far (e.g., D8 dependencies of responsive_menu) will also be recognised by the Libraries module when they are installed manually. Very nice to have this working with both less.php and less.js now...

sjpagan’s picture

hi guys,
i read all list of comments, i decide help you to porting this module to D8,
I have a great need for this module, for anything do not hesitate to contact me.

My Starting repo is: https://gitlab.com/SchnWalter/drupal8-less

sjpagan’s picture

Please see this documentation : https://www.drupal.org/docs/8/understanding-drupal/directory-structure, using composer in less folder place "oyejorge/less.php" on vendor folder, this folder used only for core of drupal 8.

The correct folder for this package is libraries, the composer.json is not correct :-(

sjpagan’s picture

Hi @SchnWalter,
apply this patch to your repo, it resolve problem to location of libraries less.php in library folder and not in vendor folder, this modify create a folder named
lessphp in libraries folder, but the new name not recognized from module.

sjpagan’s picture

Status: Needs work » Needs review
ion.macaria’s picture

Priority: Normal » Major

Hello, I started to port this module into drupal 8 version with https://www.drupal.org/project/libraries.
All was ok, but when I tried to use function less_element_info_alter(&$type) it reminded me about new style (.libraries.yml) implementation. I don't know how we can alter our style.less element and put a pre_render function on it. Some ideas?
Drupal 7 function:

/**
 * Implements hook_element_info_alter().
 */
function less_element_info_alter(&$type) {
  
  kint($type);
  // Prepend to the list of #pre_render functions so it runs first.
  array_unshift($type['styles']['#pre_render'], '_less_pre_render');

  if (variable_get(LESS_DEVEL, FALSE)) {
    
    // Must run after drupal_pre_render_styles() to attach any attributes.
    array_push($type['styles']['#pre_render'], '_less_attach_src');
  }
}

PS: Sorry for my english.

ion.macaria’s picture

I'm glad to announce about first "Less CSS Preprocessor" module - drupal 8 version.
This works with Libraries API and you can include all less libraries like in drupal 7 version. Also it works with autoprefixer (v5.0 was tested).
This module will detect yml library with "less" name.

Example:
theme_name.libraries.yml

less:
  css:
    theme:
      less_file_path/file_name.less: {}

and you can include it on needed pages:

Example(global use):
theme_name.info.yml

libraries:
  - 'theme_name/less'

Module URL: https://www.drupal.org/node/2619554

ion.macaria’s picture

Issue summary: View changes
frob’s picture

Can we get this code back onto drupal.org? It is a huge problem when efforts are split or duplicated in several disconnected repos.

@ion.macaria, this issue is marked needs review. The best way to help is to review the code that is already in place.

@corey.aufang, can this code be brought back into drupal.org so that confusion stops on which version to use? I want to review this, but I have no idea what I am supposed to review at this point.

frob’s picture

Issue summary: View changes
frob’s picture

Status: Needs review » Needs work

This review is from https://gitlab.com/SchnWalter/drupal8-less 7825689a21466c564f6fa084af39e194c2f97ee7

The module seems to work. I would say it is defiantly ready for a dev release. I have two issues,

  1. the documentation is full of cruft
  2. I still have to rebuild the cache everytime I make a change
SchnWalter’s picture

We've been using a version of the module in production on a couple of sites for about 8 month now, and I've made some improvements to help with development. I'll push some updates to the github repo next week, or I'll submit a patch if a 'dev' release is made on D.o

ion.macaria’s picture

@frob I have no time, but this month i will try to create a README file, and review code for first stable version.

frob’s picture

@ion.macaria please combine forces with @SchnWalter. https://gitlab.com/SchnWalter/drupal8-less is farther along and should be brought to d.o

ion.macaria’s picture

I started to test https://gitlab.com/SchnWalter/drupal8-less module, but after installation i got this error.
Uncaught PHP Exception Drupal\\Component\\Plugin\\Exception\\PluginNotFoundException: "The "" plugin does not exist." at ...\\core\\lib\\Drupal\\Component\\Plugin\\Discovery\\DiscoveryTrait.php line 52
Someone know what's the problem?

Update:
This happens where I try to access admin/config page and none library is activated.

frob’s picture

@ion.macaria that sounds like a legitimate bug. I think I may have run into it to but figured it was another a problem with something else I was working on.

Did you try requiring the less lib with composer? If I remember right I ran a cache rebuild and that cleared it up. There might be a bug with the code that causes an error when there are no libraries installed/detected.

ion.macaria’s picture

Module https://gitlab.com/SchnWalter/drupal8-less works ok.

@frob I can't found issue 2 (I still have to rebuild the cache everytime I make a change),
but I saw module is not working where CSS is aggregated.

Anyway, this module saved me a long time in D7, because I did not have to reload the page. I want to say, we have to implement watch mode! Otherwise this module is useless, because alternative can be gulp on node.js.

This week I will start to avoid CSS aggregation, after that - implementing watch mode.

frob’s picture

@ion.macaria Read comments 26-29 regarding watch mode. maybe put your efforts into making watch mode work rather than reimplementing the entire module.

All I am saying is that we should be working together. It would be easier if we had an actual patch for d8 to bring it back into drupal.org

ion.macaria’s picture

The problem in CSS aggregation was devel mode. I omit it if CSS aggregation is turned on.
Here is a patch.

ion.macaria’s picture

FileSize
53.1 KB

First version with less watch, I know this is not the best code, but can be the beginning.
It's a lot of changes and I think patching is not the best approach.
So, I will put the code here.

RgnYLDZ’s picture

I added module in #56 but I get an error like this ;

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" plugin does not exist. in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 52 of /home/xxxxxx/public_html/xxxxxx.com/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).

I get this error when I try to access the Reports page.

I installed lessphp library into the libaries folder in root.

nick_obukhov’s picture

The module from #56 does not compile less wih LESS developer mode = ON (tried with Bootstrap theme /without CDN provider/).

Murz’s picture

I have found https://www.drupal.org/project/ipless project - can it be used as alternative of LESS module for Drupal 8, or it implement another functional?

sjpagan’s picture

I have create new module with less & scss compiler in same module, plese see it to https://www.drupal.org/project/style_management

Pawlus’s picture

@sjpagan It requires composer, so it's unusable on shared hosts. Should make use of libraries instead. Then again, from what I've seen you just barely can operate Drupal without composer, so I guess there's no helping it.

frob’s picture

@Pawlus, just because a module requires composer doesn't make it not work on shared hosts. Install with composer locally and then upload the vendors directory to your shared host. Every site should use composer to manage dependencies.

Pawlus’s picture

@frob In your scenario it's almost certain to run into invalid or forbidden path in autoload.php file, because shared hosts usually overwrite root path. And to fix that you need to run composer, which is either inaccessible or called from ambiguous location, often with php version different than in your installation location. Many shared hosts don't even provide shell access. Not to mention EOL for Drupal 8 is upon us and Drupal 9 has such high requirements basically no shared host can fulfill them.

But there's no point of arguing here about that. Back on topic at hand, I'm using module called Style management mentioned in #60. It's not perfect by any means, but it gets the job done, it could use source mapping. Also it uses less.php instead of lessphp, which is outdated.