python - Autoprefixer Filter Not Working in Flask_Assets -


i have tried autoprefixer filter work flask_assets following instructions in flask_assets documentation, not appear apply filter. here code:

# construct flask app object flask import flask, render_template_string flask_args = { 'import_name': __name__ } flask_app = flask(**flask_args)  flask_assets import environment, bundle assets = environment(flask_app) assets.config['autoprefixer_bin'] = 'postcss' assets.config['autoprefixer_browsers'] = [ '> 1%' ] css_min = bundle('../styles/mycss.css', filters='autoprefixer', output='styles/test.css') assets.register('css_assets', css_min)  @flask_app.route('/') def landing_page():     html = '<!doctype html public "-//w3c//dtd html 3.2 final//en">\             <head>{% assets "css_assets" %}\             <link rel="stylesheet" href="{{ asset_url }}" type="text/css">\             {% endassets %}\             <title>hello</title>\             </head>\             <h1>hello world</h1>\             <p>just test of flask</p>'     return render_template_string(html), 200  if __name__ == '__main__':     flask_app.run(host='0.0.0.0', port=5000) 

i have been able apply cssmin, pyscss, uglifyjs , jsmin filters successfully. can run autoprefixer on command line compile transformed output:

postcss --use autoprefixer --autoprefixer.browsers "> 1%" -o test.css mycss.css 

however, when trying run autoprefixer through flask_assets registration, process neither throws error nor seem take required time compile. produce output file when examine resulting file, none of prefixes have been applied.

update: problem seems occur whenever attempting configure options filter. have not been able uglifyjs accept 'uglifyjs_extra_args' or pyscss filter adopt new style using 'pyscss_style' either. have tried set these configuration environmental variables using os.environ['autoprefixer_bin'] attempting pass them through flask.config['autoprefixer_bin']. none of configuration settings have been applied when filter run. not clear me in code configuration options constructed either bundle or environment.

one post claims have found way configuration setting work, post not show entire workflow of how flask_assets needs setup ingest these options.

perhaps can me understand doing wrong?

autoprefixer:

there nothing wrong code1. not using correct filter latest version of autoprefixer. if @ history of releases in link, since version 6.0.0, started using . code work versions older 6.0.0.

webassets has provided support versions after 6.0.0 (inclusive), providing autoprefixer6 filter.

therefore have change filter(s) while initializing bundle, so:

css_min = bundle('../styles/mycss.css', filters='autoprefixer6', output='styles/test.css') 

other filters' configurations:

don't use os.environ, not way set configuration variables flask , . common (and preferred) way set configuration extensions using flask config itself, , in large projects done using separate config file. extensions pickup configuration options flask's config.

depending on extension use, can set config separately have done, used, have seen far.

please check flask's configuration related documentation examples on how setup configuration app "properly".


from flask import flask, render_template_string flask_assets import environment, bundle  # construct flask app object flask_args = {'import_name': __name__} flask_app = flask(**flask_args)  assets = environment(flask_app) # specify bin path (optional), required if not globally installed  assets.config['autoprefixer_bin'] = 'path/to/postcss' assets.config['autoprefixer_browsers'] = ['> 1%', ] # use autoprefixer6 updated filter css_min = bundle('../styles/mycss.css', filters='autoprefixer6',                  output='styles/test.css') assets.register('css_assets', css_min)   @flask_app.route('/') def landing_page():     html = '<!doctype html public "-//w3c//dtd html 3.2 final//en">\             <head>{% assets "css_assets" %}\             <link rel="stylesheet" href="{{ asset_url }}" type="text/css">\             {% endassets %}\             <title>hello</title>\             </head>\             <h1>hello world</h1>\             <p>just test of flask</p>'     return render_template_string(html), 200   if __name__ == '__main__':     flask_app.run(host='0.0.0.0', port=5000) 

remember clean out generated files, if source css/js has not changed, i.e remove output files, , .webassets-cache folder.

1except code style & formatting conventions!


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -