1

Using , , I am trying to pass a filter specific configuration for a particular filter in webassets, but haven't been able to do so, so far.

Have read the documentation multiple times to no avail. Have also gone through the source code, but that hasn't helped either.

Specifics:

  • The filter I'm trying to use is cleancss
  • And the particular configuration I'm trying to pass is --skip-rebase

According to the link to cleancss docs above, I should be able to pass the --skip-rebase option in CLEANCSS_EXTRA_ARGS. But where do I put that?

What I've tried so far, passing as flask config variables:

CLEANCSS_EXTRA_ARGS = ['--skip-rebase']  # actually works, see answer!
CLEANCSS_EXTRA_ARGS = ['skip-rebase']  # doesn't work!
ASSETS_CLEANCSS_EXTRA_ARGS = ['--skip-rebase']  # doesn't work!
FLASK_ASSETS_CLEANCSS_EXTRA_ARGS = ['--skip-rebase']  # doesn't work!
ASSETS_CLEANCSS_EXTRA_ARGS = ['skip-rebase']  # doesn't work!
FLASK_ASSETS_CLEANCSS_EXTRA_ARGS = ['skip-rebase']  # doesn't work!

ps: I also tried modifying the source to check if cleancss parameters are being correctly passed to the command line, and it is, so the problem is only in specifying the option correctly in the app configuration.

bool.dev
  • 17,508
  • 5
  • 69
  • 93

1 Answers1

1

On retrying with the first option in question:

CLEANCSS_EXTRA_ARGS = ['--skip-rebase']

It worked!

More info available in the flask assets repo issues.

In my hurry I must have tried with:

CLEANCSS_EXTRA_ARGS = ['skip-rebase']

which didn't work and hence the question.


This feature should be documented though. Will probably submit a pull request for doc improvement.


Also note that this requires version 0.11 (webassets) and above.

bool.dev
  • 17,508
  • 5
  • 69
  • 93
  • currently kicking myself for wasting time on trying other things, when my first try would have been correct! – bool.dev Apr 04 '16 at 14:15
  • Can you please post a more complete example for how either app or assets ingests these configuration options? There is no documentation about how one properly adds an option as a property for a filter. An example of my problem: https://stackoverflow.com/questions/42281671/autoprefixer-filter-not-working-in-flask-assets – R J Mar 09 '17 at 05:54
  • @RJ sure, but gimme sometime – bool.dev Mar 09 '17 at 12:49
  • thanks. Since the system fails gracefully, I'm still not sure how to pass the configuration options into the constructor, or even precisely which object to add it to. Neither assets.config['OPTION'] nor app.config['OPTION'] nor os.environ['OPTION'] seems to work for me. – R J Mar 09 '17 at 17:41
  • @RJ, how these configurations are ingested by the library, is actually beyond the scope of this question, but if you want to see that, you can just head over to the source of the specific filter for example: [autoprefixer](https://github.com/miracle2k/webassets/blob/master/src/webassets/filter/autoprefixer.py#L47). With regards to your [specific question](http://stackoverflow.com/q/42281671/720508), I will be adding an answer there shortly, to help you along the way. – bool.dev Mar 10 '17 at 09:01
  • @RJ, also added tips to add configuration correctly in Flask, to my [answer](http://stackoverflow.com/a/42715890/720508) to your question. I try to be thorough :) – bool.dev Mar 10 '17 at 10:35