PHPackages                             baldwin/magento2-module-less-js-compiler - 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. baldwin/magento2-module-less-js-compiler

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

baldwin/magento2-module-less-js-compiler
========================================

Allows Magento 2 to compile less files using the less nodejs compiler

v1.7.1(1y ago)2348.6k↓30.4%4MITPHPPHP ~5.5.0 || ~5.6.0 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0CI failing

Since Jun 2Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/baldwin-agency/magento2-module-less-js-compiler)[ Packagist](https://packagist.org/packages/baldwin/magento2-module-less-js-compiler)[ RSS](/packages/baldwin-magento2-module-less-js-compiler/feed)WikiDiscussions v1-develop Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (20)Used By (0)

Magento 2 module which allows compiling less files using the less.js compiler
=============================================================================

[](#magento-2-module-which-allows-compiling-less-files-using-the-lessjs-compiler)

Description
-----------

[](#description)

This module was built out of frustration about the slow deployments of static assets to a production environment while running `bin/magento setup:static-content:deploy`. In particular this module tries to tackle the slowness which comes with compiling less files using the [less.php](https://github.com/oyejorge/less.php) library, which Magento 2 uses by default.
This module provides a solution by using the [original less.js compiler](https://github.com/less/less.js) which was written in javascript and is executed through node.js
We have [benchmarked](#benchmarks) the difference between the less.php and less.js compilers, and the less.js compiler is somewhere between 1.5 and 3 times as fast as the less.php compiler, although it depends on your PHP version. If you run PHP 5.x the performance increase will be much higher, PHP 7.x is actually quite fast by itself, but the nodejs version still beats it.

**Update**: Since Magento 2.3.0, it seems like the performance differences between less.php and less.js are not very big anymore. I have the suspicion this might have something to do with newer [releases of the less.php](https://github.com/oyejorge/less.php/releases) library. Which got released somewhere around the period when Magento 2.2.3 &amp; 2.1.12 were released. So it's possible that the performance difference for Magento 2.2.x and 2.1.x might also be less significant then how it's displayed [below](#benchmarks) if you upgrade the less.php library to the latest version (v1.7.0.14 at the time of writing).
This is a bit of speculation, since unfortunately I didn't keep track of the version of the less.php library which I've used in the benchmarks, so I'm not sure about this statement.

Since Magento 2.4.0 (or newer PHP versions?), the performance differences seems to have changed in favor of less.php. But you might still want to use this module so that the outputted css is the same between your local development environment and a production environment.

Requirements
------------

[](#requirements)

You'll need at least Magento 2.0.7. We didn't bother with testing this module on older versions.
If you want to use this module, you'll need to be able to install [node.js](https://nodejs.org/) and [npm](https://www.npmjs.com/) on the machine(s) on which you will build your static assets.
You'll also need to make sure that the `node` binary is available in the `$PATH` environment variable of the user which will build the static assets.
You'll also need [composer](https://getcomposer.org/) to add this module to your Magento 2 shop.

Installation
------------

[](#installation)

First, we recommend you to install the less compiler itself, and save it into your `package.json` file as a production dependency:

```
npm install --save less@3.13.1
```

> Watch out: from Magento 2.1 onwards, the `package.json` file is being renamed to `package.json.sample` to enable you to have your own nodejs dependencies without Magento overwriting this every time with its own version each time you update Magento. So if you use Magento &gt;= 2.1 make sure you copy the `package.json.sample` file to `package.json` before running the above command if you want to work with Magento's `grunt` setup.

Then run a shrinkwrap, so the version of less (and its dependencies) are fixed, this will produce a file `npm-shrinkwrap.json` with the exact versions of all your nodejs production dependencies and their own dependencies, so you can be sure it will use those exact versions when you install this on another machine.

```
npm shrinkwrap
```

And make sure you add these two files to your version control system.

> For an analogy with composer, you can compare the `package.json` file with `composer.json`, and `npm-shrinkwrap.json` with `composer.lock`

Now install this module

```
composer require baldwin/magento2-module-less-js-compiler
```

And enable it in Magento

```
bin/magento module:enable Baldwin_LessJsCompiler
bin/magento setup:upgrade
```

As the last step, in your deploy scripts, make sure you call `npm install --production`. You should execute this somewhere between `composer install` and `bin/magento setup:static-content:deploy`

Configuration
-------------

[](#configuration)

You have the opportunity to configure the arguments we send to the `lessc` and `node` commands. The defaults are:

- `lessc --no-color`
- `node --no-deprecation`

If you want to override the default arguments, you can do this by modifying your `app/etc/config.php` or `app/etc/env.php` file and adding something like this:

```
    'system' => [
        'default' => [
            'dev' => [
                'less_js_compiler' => [
                    'less_arguments' => '--no-color --ie-compat',
                    'node_arguments' => '--no-deprecation --no-warnings',
                ]
            ]
        ]
    ]
```

You can also enable throwing an exception when the less compilation runs into warnings/errors, by default this is disabled and you should find the problems logged in your `var/log/system.log` file. But if you want to enable throwing an exception during the compilation process, you can by configuring this in your `app/etc/config.php` or `app/etc/env.php` file:

```
    'system' => [
        'default' => [
            'dev' => [
                'less_js_compiler' => [
                    'throw_on_error' => true,
                ]
            ]
        ]
    ]
```

Investigating less compilation errors
-------------------------------------

[](#investigating-less-compilation-errors)

When your `.less` files have a syntax error or contain something which doesn't allow it to compile properly, please have a look at the `var/log/system.log` file, it will contain some output about what caused the problem.

Remarks
-------

[](#remarks)

1. Installing this module will effectively replace the default less compiler from Magento2. If you want to go back to the default less compiler, you need to disable this module or uninstall it.
2. This module expects the less compiler to exist in `{MAGENTO_ROOT_DIR}/node_modules/.bin/lessc`, this is a hard coded path which is being used in the module. The compiler will end up there if you follow the installation steps above, but if for some reason you prefer to install your nodejs modules someplace else, then this module won't work. If somebody actually has this problem and wants us to make this configurable, please let me know!
3. The default less processor in Magento 2 passes an option to the less compiler, which says it should [compress the resulting css file](https://github.com/magento/magento2/blob/6a40b41f6281c7d405cd78029d6becab1d837c87/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Processor.php#L73). In this module, we have chosen not to do so, as we believe this isn't a task to be executed while compiling less files. It should be done further down the line, like for example during the minification phase. If someone disagrees with this, please let me know, I'm open to discussion about this.
4. This module was tested against Magento versions 2.0.7, 2.1.x, 2.2.x, 2.3.x, 2.4.x

Benchmarks
----------

[](#benchmarks)

### Intro

[](#intro)

This is by no means very professionaly conducted, but here are some tests performed on some Magento 2 shops we are working on.
We disabled parallelism to make the comparison between different Magento versions easier to understand.
We only measured the duration of the `bin/magento setup:static-content:deploy` command, xdebug is disabled as it causes a massive slowdown, and before every run we make sure all caches are clean, by running:

```
rm -R pub/static/* var/cache/* var/view_preprocessed/* var/generation/* var/di/* var/page_cache/* generated/*
```

### Machines

[](#machines)

- The *older* server is a server which is in constant use and has older software installed on it.
- The *newer* server is a new server which currently receives no traffic and has al the sparkly new software versions installed (at the time of writing).
- The *older-local* machine is a 2011 Macbook Pro (HDD has been upgraded to SSD, no vagrant or docker, just native software using Macports)
- The *newer-local* machine is a 2017 Macbook Pro (native software using Homebrew or Macports)

### Results

[](#results)

magentothemeslocalesstrategymachinephpnodejsless.phpless.js2.0.751-older5.5.300.10.338m22s**3m14s**2.0.752-older5.5.300.10.3316m24s**6m11s**2.0.743-older5.5.300.10.3318m44s**6m26s**2.0.751-newer7.0.74.2.61m30s**1m00s**2.0.752-newer7.0.74.2.63m06s**1m51s**2.0.753-newer7.0.74.2.64m52s**2m52s**2.1.0-rc131-older-local5.5.364.4.34m39s**2m01s**2.1.0-rc131-older-local5.6.224.4.34m17s**2m02s**2.1.0-rc131-older-local7.0.74.4.32m01s**1m26s**2.1.931-newer-local7.0.234.8.42m35s**1m14s**2.1.932-newer-local7.0.234.8.42m44s**1m05s**2.2.031standardnewer-local7.0.234.8.41m42s**0m38s**2.2.031quick\*newer-local7.0.234.8.41m42s**0m38s**2.2.031compactnewer-local7.0.234.8.41m42s**0m38s**2.2.032standardnewer-local7.0.234.8.43m30s**1m05s**2.2.032quick\*newer-local7.0.234.8.43m29s**1m07s**2.2.032compactnewer-local7.0.234.8.41m52s**0m40s**2.3.032standardnewer-local7.2.128.12.01m35s**1m26s**2.3.032quick\*newer-local7.2.128.12.01m35s**1m28s**2.3.032compactnewer-local7.2.128.12.00m43s**0m42s**2.4.032standardnewer-local7.4.48.17.0**0m49s**0m58s2.4.032quick\*newer-local7.4.48.17.0**0m49s**1m03s2.4.032compactnewer-local7.4.48.17.0**0m31s**0m37s*\** The [quick strategy](http://devdocs.magento.com/guides/v2.4/config-guide/cli/config-cli-subcommands-static-deploy-strategies.html) deployment is [currently bugged in Magento 2.2.x and 2.3.x and 2.4.x](https://github.com/magento/magento2/issues/10674) and behaves the same as the standard strategy

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance67

Regular maintenance activity

Popularity39

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity89

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 87.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~231 days

Recently: every ~95 days

Total

15

Last Release

405d ago

PHP version history (9 changes)v1.0.0PHP ~5.5.0|~5.6.0|~7.0.0

v1.1.0PHP ~5.5.0|~5.6.0|7.0.2|7.0.4|~7.0.6|~7.1.0

v1.2.0PHP ~5.5.0|~5.6.0|7.0.2|7.0.4|~7.0.6|~7.1.0|~7.2.0

v1.3.0PHP ~5.5.0 || ~5.6.0 || 7.0.2 || 7.0.4 || ~7.0.6 || ~7.1.0 || ~7.2.0 || ~7.3.0

v1.4.0PHP ~5.5.0 || ~5.6.0 || 7.0.2 || 7.0.4 || ~7.0.6 || ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0

v1.5.0PHP ~5.5.0 || ~5.6.0 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.1.0

v1.5.1PHP ~5.5.0 || ~5.6.0 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.1.0 || ~8.2.0

v1.5.2PHP ~5.5.0 || ~5.6.0 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.1.0 || ~8.2.0 || ~8.3.0

v1.7.1PHP ~5.5.0 || ~5.6.0 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1d62cd17eb7811ff24ce4c4356f63182f29a910c80294eeef17d866a29bdea35?d=identicon)[baldwin](/maintainers/baldwin)

---

Top Contributors

[![hostep](https://avatars.githubusercontent.com/u/85479?v=4)](https://github.com/hostep "hostep (94 commits)")[![baldwinagency-pieter](https://avatars.githubusercontent.com/u/4758823?v=4)](https://github.com/baldwinagency-pieter "baldwinagency-pieter (10 commits)")[![piotrkwiecinski](https://avatars.githubusercontent.com/u/2151333?v=4)](https://github.com/piotrkwiecinski "piotrkwiecinski (2 commits)")[![Echron](https://avatars.githubusercontent.com/u/2070180?v=4)](https://github.com/Echron "Echron (1 commits)")

---

Tags

magento2magento2-extensionmagento2-modulemagentolesscompilermagento2

### Embed Badge

![Health badge](/badges/baldwin-magento2-module-less-js-compiler/health.svg)

```
[![Health](https://phpackages.com/badges/baldwin-magento2-module-less-js-compiler/health.svg)](https://phpackages.com/packages/baldwin-magento2-module-less-js-compiler)
```

###  Alternatives

[opengento/module-gdpr

Gdpr Compliance Module for Magento 2

14481.5k](/packages/opengento-module-gdpr)[run-as-root/magento2-prometheus-exporter

Magento2 Prometheus Exporter

69344.4k](/packages/run-as-root-magento2-prometheus-exporter)[friends-of-hyva/magento2-crawler-session

Prevent crawlers from creating a session

155.8k](/packages/friends-of-hyva-magento2-crawler-session)[opengento/module-saleable

This extension allows to set if a product is saleable and can show its price by scope and customer group.

136.9k](/packages/opengento-module-saleable)[maisondunet/module-gtm-cookie-consent

A simple cookie consent module for magento. It relies on new GTM consent functionality.

134.5k](/packages/maisondunet-module-gtm-cookie-consent)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
