What this solution does
The LESS compiler module is designed for frontend developers who use concise syntax with shared variables and nested class hierarchies. Code examples demonstrate the definition of color variables and element styling with media query support for responsive design.
The module handler subscribes to the main/OnProlog system event, which is registered during installation via RegisterModuleDependences. This ensures automatic processing on every request without the need for manual file inclusion.
When the module is active, the system scans the site's file structure to collect all .less files. By default, directories such as bitrix/, upload/, vendor/, node_modules/, and .git/ are excluded, though this exclusion list can be configured in the administrative panel.
The module compiles LESS files according to a manual list. To track changes, a state fingerprint is calculated for each file, including the path, last modification time, and size. If the fingerprint matches the saved one and the compiled style.css file already exists, no rebuild is triggered, and the page receives a link to the ready resource. When the fingerprint changes due to adding, deleting, or editing a file, the files are recompiled via Less_Parser, and the result atomically replaces the old style.css. The final file is saved to the /upload/ecl_lesscompiler/SITE_ID/style.css directory, where SITE_ID is the unique site identifier. Connection is performed in the head section via a separate link tag using the $APPLICATION->SetAdditionalCSS() method, independently of other site CSS templates. In composite site mode, the handler accesses only the file system and adds a link to a static file. When generating a composite page snapshot, this link tag is included in the cached HTML, and the browser subsequently requests the style.css file directly, bypassing PHP. The composite caching mechanism remains unaffected. The directory scan in 'all files' mode is additionally cached for 60 minutes via Bitrix\Main\Data\Cache to avoid traversing the directory tree on every hit. The 'Force rebuild now' button in settings clears this cache and triggers immediate CSS recompilation.
Compilation errors in LESS, including syntax errors or missing @import directives, are logged to the Bitrix event log. This prevents the page from breaking. If a working style.css file was previously compiled, the system serves that existing file.
General iT can install “LESS compiler (EcomLabs)”, configure its settings and verify its operation in the existing project.