langemike / laravel5-less by langemike

Bringing lessphp into Laravel
5,576
4
1
Package Data
Maintainer Username: langemike
Maintainer Contact: mikevv@gmail.com (Mike van Veenhuijzen)
Package Create Date: 2015-10-08
Package Last Update: 2020-08-14
Language: PHP
License: MIT
Last Refreshed: 2020-10-23 15:32:55
Package Statistics
Total Downloads: 5,576
Monthly Downloads: 25
Daily Downloads: 0
Total Stars: 4
Total Watchers: 1
Total Forks: 5
Total Open Issues: 3

LESS support for Laravel 5.x without Node.js

Use LESS with your Laravel installation. Uses oyejorge/less.php instead of leafo/lessphp which is a more actively developed port of the official LESS processor.

Features

  • Can modify LESS variables on-the-fly
  • Can parse custom CSS/LESS and append it to the resulting file
  • Works with Twitter Bootstrap v3.3.5 (thanks to oyejorge/less.php)
  • Caching support

Installation

First, pull in the package through Composer.

"require": {
    "langemike/laravel5-less": "~1.0"
}

Note: The following installation instructions are longer required with Laravel 5.5.

If using Laravel 5 up to 5.4, include the service provider within config/app.php.

'providers' => [
    'Langemike\Laravel5Less\LessServiceProvider'
];

In the aliases section, add:

'aliases' => [
    'Less' => 'Langemike\Laravel5Less\LessFacade'
];

Configuration

In order to work with the configuration file, you're best off publishing a copy with Artisan:

$ php artisan vendor:publish

This will create a config file 'less.php' in your config directory.

Settings

You can specify your configuration through 3 options: .env, config.php file and through $options parameter.

Your .env configuration will be used by default, it will be overridden by it's config.php settings, but the $options parameter will have the highest preference.

Recompilation

Additionally you can (and probably should) have different configurations for development and production. Specifically, you probably don't want to be generating css files on your production server, since it will slow down your site.

  • change -- Check if LESS file(s) are modified. If it does, recompile CSS
  • none -- Don't check, don't recompile.
  • always -- Always rewrite CSS

Usage

Within your models or controllers, you can perform modification to the outputted CSS. Here are some examples: before you perform a redirect...

public function recompileCSS()
{
    Less::modifyVars(['@body-bg' => 'pink'])->recompile('filename');

    return Redirect::back();
}

Within your view you can use the Less::url() function to link to your generated CSS

	<link href="{!! Less::url('filename') !!}" rel="stylesheet" />

Passing true as the second parameter to Less::url() will auto-detect, based on your configuration, if recompilation is needed and will do so accordingly.

Credits

This project is inspired by Less4Laravel. Without the hard work of oyejorge/less.php this project wouldn't be possible.