PHPackages                             i-lateral/silverstripe-lesscompiler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. i-lateral/silverstripe-lesscompiler

ActiveSilverstripe-module[Utility &amp; Helpers](/categories/utility)

i-lateral/silverstripe-lesscompiler
===================================

A simple less compiler that runs on Silverstripe execution

0.3(6y ago)070011BSD-3-ClausePHP

Since May 19Pushed 6y ago3 watchersCompare

[ Source](https://github.com/i-lateral/silverstripe-lesscompiler)[ Packagist](https://packagist.org/packages/i-lateral/silverstripe-lesscompiler)[ Docs](http://github.com/i-lateral/silverstripe-lesscompiler)[ RSS](/packages/i-lateral-silverstripe-lesscompiler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (1)

Silverstripe Lesscompiler Module
================================

[](#silverstripe-lesscompiler-module)

A module that compiles defined less files on execution and exportes them to a defined CSS file.

Currently this is a proof of concept and has lots of possible options for expansion.

This module uses the ["less.php"](https://github.com/oyejorge/less.php)module to compile less files. If not installing via composer you will need this installed to your path.

Installation via Composer
-------------------------

[](#installation-via-composer)

```
composer require i-lateral/silverstripe-lesscompiler 0.*

```

Operation
---------

[](#operation)

This module checks for updates to defined less files before controller initilisaton. If there are changes then new CSS is compiled and saved to the defined output path.

This process is only run on dev (as to not detrimentally effect performance on live sites) and all cache files are stored in the default Silverstripe temp directory.

Basic usage
-----------

[](#basic-usage)

Start off by setting the file\_mappings config variable on LessCompilerConfig. This should be a list of less files to convert with their equivilent export file, eg:

config.yml

```
LessCompilerConfig:
  file_mappings:
    "styles.less": "styles.css"
    "typography.less": "typography.css"

```

\_config.php

```
LessCompilerConfig::config()->file_mappings = array(
    "styles.less" => "styles.css",
    "typography.less" => "typography.css"
);

```

If you do not include a path to the less/css files then the module assumes that you are using the default theme directory and using folders named "less" and "css" respectively.

Custom file paths
-----------------

[](#custom-file-paths)

You can define custom less and css file paths but using the following:

config.yml LessCompilerConfig: file\_mappings: "themes/themename/less/styles.less": "themes/themename/css/styles.css" "themes/themename/less/typography.less": "themes/themename/css/typography.css"

\_config.php

```
LessCompilerConfig::config()->file_mappings = array(
    "themes/themename/less/styles.less" => "themes/themename/css/styles.css",
    "themes/themename/less/typography.less" => "themes/themename/css/typography.css"
);

```

Compressing output
------------------

[](#compressing-output)

By default all output is compressed, this can be disabled using the "compress" config variable, EG:

config.yml

```
LessCompilerConfig:
  compress: false

```

\_config.php

```
LessCompilerConfig::config()->compress = false;

```

Relative image URLS
-------------------

[](#relative-image-urls)

The compiler attempts converts all relative image URLs to be prefixed prefixed with ../ (this assumes that the output css will be in a seperate folder to the images, but with a common root). This can be altered using the "root\_path" config variable

config.yml

```
LessCompilerConfig:
  root_path: "../../imports"

```

\_config.php

```
LessCompilerConfig::config()->root_path = "../../imports";

```

Before and After Compile extensions
-----------------------------------

[](#before-and-after-compile-extensions)

If you need to perform custom functions just before or after Less Compiler runs you can do this using the `onBeforeLessCompiler` and `onAfterLessCompiler`extension calls.

**NOTE** These calls are added to controller, so rather than adding an extension to LessCompiler itself, you only need to add your custom code to an extension to Controller. EG:

app/code/extensions/AppControllerExtension.php

```
