2

I have simply tried setting up flask-assets (based on webassets), however just can't get it to work.

I have the standard setup;

  • python virtualenv
  • pip to install the bare essentials (flask, flask-assets)
  • sass ruby gem (for trying sass / scss)
  • less via npm (for trying lesscss)
  • jsmin via pip (for trying jsmin)

Config:

  • I have created a working homepage in Flask
  • static folder created (for css / js assets)
  • The css / js files are confirmed working (css background, js slider, etc)
  • Basically my development non-flask-assets site is working perfectly

I have followed the easy official guide here: flask-assets usage. I fully understand how to work with it (as per that page). I have even exact copy-pasted the code, & still can't get it working.

Some code I've tried (for lesscss): (of course I have working css in main.less)

from flask.ext.assets import Environment, Bundle
assets = Environment(app)
assets.debug = True

lesscss = Bundle('main.less', output='main.css', filters='less')
assets.register('less', lesscss)

Then in my template:

{% assets "less" %}
<link href="{{ ASSET_URL }}" rel="stylesheet">
{% endassets %}

However flask-assets just won't work. I've tried the same with sass, scss, & also jsmin (exact code copy-paste from the usage guide) - it still won't work.

  • I notice that the .webassets-cache folder is created, but is (always) empty...

Also; relevant error?; I expect it to create the main.css, but as it doesn't, I get an error in the browser (using app.debug = True & flask's built-in dev server):

webassets.exceptions.BuildError
BuildError: Nothing to build for <Bundle output=css/main.css, filters=[<webassets.filter.less.Less object at 0x7f4958dc6710>], contents=('css/main.less',)>, is empty

So; If I manually create an empty main.css, it loads the page (no error), however the main.css file is not filled with css so flask-assets / webassets in still not working.

I've also tried passing the assets object to the template in various ways just in case it's needed (although no documentation states this) - that didn't work.

It's been driving me crazy. Any pointers would be appreciated.
Thank you

SiNGH
  • 31
  • 1
  • 4
  • You can't be using both LESS and Sass, which one are you actually working with? – cimmanon Apr 26 '15 at 19:15
  • I wanted Sass. So I tried to use it = not working. My debugging process to see if it's just Sass not working, or other stuff too... So I tried SCSS = not working. So I tried lesscss = not working. So I tried the exact example on the flase-assets site (jsmin) = not working. – SiNGH Apr 26 '15 at 20:18
  • Do you have debug turned on in Flask? – dirn Apr 27 '15 at 00:35
  • I do... (I've tried both with & without debug). Without debug I simply get a generic _"Internal Server Error"_ page (nothing useful), but with debug I get the _BuildError_ message in my question... – SiNGH Apr 27 '15 at 11:11

1 Answers1

1

There is info missing on the Flask-Assets docs. You problem is either the sass_bin config or the enviroment load path. You should try both, in my case it was the config. See below my working config.

PS: IMHO Flask Assets is neither very complete nor well documented. It also consumes you application runtime, which sucks both on debugging and production. I have switched to GULP!

 env = Environment(app)
 env.config['sass_bin'] = '/usr/local/bin/sass'
 # env.load_path = [os.path.join(os.path.dirname(__file__), 'sass')]
 js = Bundle('js/jquery/jquery-2.1.4.js', 'js/angular/angular.js',
             'js/socketio/socket.io.js', filters='jsmin', output='js/all_min.js')
 env.register('js_all', js)
 myjs = Bundle('myjs/Interpolation.js', 'myjs/socketio.js' , filters='jsmin', output='myjs/all_min.js')
 env.register('myjs_all', myjs)
 css = Bundle('sass/base.sass', filters='sass', output='css/base.css')
 env.register('css_all', css)
CESCO
  • 7,305
  • 8
  • 51
  • 83