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.
Take a look at DukPy! It's a simple javascript interpreter for Python and can compile CoffeeScript
, TypeScript
, BabelJS
and JSX
. Usage is very simple:
import dukpy
dukpy.coffee_compile("CoffeeScript goes here!")
DukPy is the successor to the Python-CoffeeScript package witch is no longer maintained.
© 2022 - 2024 — McMap. All rights reserved.