noob here. I was trying to crunch my javascript files using flask assets but unfortunately my view rendered all the javascript files as separate links and not as one minified file.
Here is my code and file structure. Please help me learn.
import os
from flask import Flask
from flask.ext.assets import Environment , Bundle
from main.views import main
from webassets.loaders import PythonLoader
app = Flask(__name__)
assets = Environment(app)
app.register_blueprint(main, url_prefix='/')
#Compress All Assets
js = Bundle('javascripts/main.js',
'javascripts/plugins.js',
'javascripts/vendor/jquery-1.9.1.min.js',
'javascripts/vendor/modernizr-2.6.2.min.js',
filters='jsmin', output='gen/packedjs.js')
assets.register('js_all', js)
css = Bundle('stylesheets/css/main.css',
'stylesheets/css/normalize.css',
filters='sass,less,cssmin', output='gen/packedcss.css')
assets.register('css_all', css)
This is my code in index.html
{% assets "css_all" %}
<link rel="stylesheet" href="{{ ASSET_URL }}">
{% endassets %}
{% assets "js_all" %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}
My file structure of css and javascript files.
To fix this problem install jsmin manually. Just do as follow:
pip install jsmin
Or as you will:
easy_install jsmin
I hope i've helped you. Be happy!
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