Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue using Flask-Assets to compile less files

I'm currently trying to set up a Flask web app, and trying to use Flask-Assets to compile my less files into minified css.

Here is my assets.py file that creates the bundle.

from flask_assets import Bundle

common_css = Bundle(
    'vendor/less/theme.less',
    filters='less',
    output='static/css/common.css',
    )

The error that I am getting is:

OSError: [Errno 2] No such file or directory

In the webassets documentation for the less filter, it says that:

This depends on the NodeJS implementation of less, installable via npm. To use the old Ruby-based version (implemented in the 1.x Ruby gem), see Less.

...

LESS_BIN (binary)
    Path to the less executable used to compile source files. By default, the filter will attempt to run lessc via the system path.

I installed less using $ npm install less, but for some reason it looks like webassets can't use it.

When I try to use different filters, then webassets can successfully create the bundle.

Thanks!

like image 238
Paul Benigeri Avatar asked Feb 02 '14 06:02

Paul Benigeri


1 Answers

npm install installs packages in current directory by default (you should be able to find node_modules directory there). You have two choices:

  1. Install lessc globally:

    $ npm install -g less
    

    This way webassets will be able to find it itself.

  2. Provide a full path to lessc executable:

    assets = Environment(app)
    assets.config['less_bin'] = '/path/to/lessc'
    

    The path should be <some_directory>/node_modules/.bin/lessc.

like image 191
Audrius Kažukauskas Avatar answered Sep 27 '22 22:09

Audrius Kažukauskas