I have a Flask app that I'm running in production. Right now it has a big ugly js file that I'd like to break out and rewrite in something like Coffeescript. I was considering something like Flask-Cake to simplify the CoffeeScript compilation. However, I don't know how something like that would work for production. I should probably have a script that compiles the coffeescript files before deploying, right? I've never worked on a system with this particular layout -- uncompiled server-side but compiled client-side. What's the standard procedure here?
You are probably looking for Flask-Assets.
Example from the website:
from flask import Flask
from flask.ext.assets import Environment, Bundle
app = Flask(__name__)
assets = Environment(app)
js = Bundle('jquery.js', 'base.js', 'widgets.js',
filters='jsmin', output='gen/packed.js')
assets.register('js_all', js)
This would automatically concatenate jquery.js
, base.js
and widgets.js
in your static
folder, pipe them through jsmin
and save the result in static/gen/packed.js
.
This compilation is by default always happening when one of the source files changes. Watching the files in production is kinda expensive in production (and would require a coffeescript compiler to be installed on the server!), so there is a configuration value to disable the monitoring.
Another plugin that is more lightweight, but in my experience also less powerful is Flask-Makestatic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With