FinnM
FinnM

Reputation: 411

How do I pass libsass configuration variables into a flask_assets bundle?

My goal is to set LIBSASS_STYLE="expanded" via flask_assets.Bundle. The webassets libsass documentation says I can do it, but doesn't say how.

My base app controller looks like the following.

from flask import Flask, render_template
from flask_assets import Environment, Bundle

app = Flask(__name__)

# ... Typical flask controller stuff

if __name__ == "__main__": 
    assets = Environment(app)

    css = Bundle(
        'sass/*.scss',         # input scss files
        filters='libsass',     # to be compiled by libsass
        output='css/style.css' # and outputed to style.css
    )

    assets.register("asset_css", css)

    app.run(debug=True)

This outputs a valid css file (which is great) but not in the format that I desire since I simply have no idea where I can slip any libsass options.

Any help on this issue is greatly welcome. Thanks!

Upvotes: 2

Views: 489

Answers (1)

Marcel Greter
Marcel Greter

Reputation: 275

You need to instantiate libsass filter explicitly to pass options to it

from flask_assets import Bundle
from webassets.filter import get_filter

libsass = get_filter(
    'libsass',
    as_output=True,
    style='compressed',
)

css = Bundle(
    'sass/*.scss',
    filters=(libsass),
    output='css/style.css'
)

Upvotes: 1

Related Questions