Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make Flask-Assets regenerate SCSS every request when debug mode is enabled?

Here is how I set up flask-assets for scss:

def configure_extensions(app):
  # Web Assets
  from app.extensions import assets
  scss = Bundle(
    'scss/all.scss',
    filters='scss',
    output='scss_all.css'
  )
  assets.register('scss_all', scss)
  assets.init_app(app)

In my config, I set ASSETS_DEBUG = True

This works, and generates the file app/static/scss_all.scss and the folder app/static/.webassets.cache. The styles appear on the site as intended.

The problem, though, is if I want to regenerate the scss style sheet, I must delete the files mentioned above. This is tedious when playing around with scss.

Is there a way to regenerate these files automatically with the reloader when app.debug is set to True?


(aside: I'm using the dev version of flask)

like image 420
corvid Avatar asked Dec 30 '25 17:12

corvid


1 Answers

This should ideally work. But incase you are using @imports to import other scss files within the main file then you need to add the depends option. Something like;

mycss = Bundle(
    'app.scss',
    filters='pyscss,cssprefixer', depends=('/path/to/scss/files/**/*.scss'), output='generated/css/app.css')
assets.register('mycss)
like image 171
Joe Ng'ethe Avatar answered Jan 03 '26 13:01

Joe Ng'ethe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!