Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Flask assets fails to compress my asset files

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.

  • static
    • gen (folder)
  • Javascript (folder)
    • javascript file 1
    • javascript file 2
    • javascript file 3
like image 839
Wesley Avatar asked Mar 23 '23 00:03

Wesley


1 Answers

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!

like image 200
Geraldo Andrade Avatar answered Apr 25 '23 06:04

Geraldo Andrade