Skip to main content

An extension to manage and serve your javascript assets with bower

Project description

Flask-Bower provides a method to manage and serve bower installed packages. This simplifies javascript dependency management a lot.

To provide this, there is a flask blueprint to serve content from your bower_components directory and use url_for() for serving the files same as serving files form flask static folder.

Usage

Flask-Bower is available on PyPi: https://pypi.python.org/pypi/Flask-Bower/

So just add it to your requirements.txt or install using pip install flask-bower

First you have to add it to your app
from flask_bower import Bower

[...]

Bower(app)
This provides the /bower url route.

Per default, the bower_components directory has to be inside the app directory (app/bower_components - like your static and templates directories). Another directory can be specified using BOWER_COMPONENTS_ROOT

Install your packages like jquery with bower: bower install -S jquery

Now it should look like:

$ ls -1 app/bower_components/jquery
MIT-LICENSE.txt
bower.json
dist
src

To include and use this, you can use url_for():

<script src="{{ url_for('bower.static', filename='jquery/dist/jquery.js') }}"></script>

Configuration

There are several configuration options to customize the behavior:

BOWER_COMPONENTS_ROOT

default: bower_components

Directory name containing your installed bower packages

BOWER_KEEP_DEPRECATED

default: True

Keep deprecated functions available

Note: deprecated functions will be removed in future versions

affected functions:

  • bower_url_for - please migrate to url_for('bower.static', filename='component/path')

BOWER_QUERYSTRING_REVVING

default: True

Append ?version= parameter to url (useful for cache busting by updates). It tries to detect the version in the following order:

  1. bower.json

  2. package.json (if available)

  3. file modification timestamp

BOWER_REPLACE_URL_FOR

default: False

Replace flasks url_for() function in templates.

This is useful - but not recommended - to build an “overlay” for the static folder.

Warning: Replacing url_for() causes conflicts with other flask extensions like flask-cdn, since only one extension can replace url_for() at a time and the last registered extension wins.

BOWER_SUBDOMAIN

default: None

Subdomain to serve the content like static (see flask blueprint documentation for subdomains)

BOWER_TRY_MINIFIED

default: True

Check if a minified version is available and serve this instead (check if a file with <filename>.min.<ext> like jquery/dist/jquery.min.js exists)

BOWER_URL_PREFIX

default: /bower

Customize the url prefix

Deprecations

bower_url_for(component, file)

This is now deprecated since it is a break of the development workflow due to the use of a different function than url_for(), which is the default for url handling in flask.

Since v1.1.0 it is possible to use the default url_for() function also for flask assets::
url_for('bower.static', filename='component/path')

Use of this new approach is recommended to all developers and to simplify the migration the bower_url_for() function will stay available for a while; though it can be disabled to help migrating (see BOWER_KEEP_DEPRECATED)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask-Bower-1.3.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distributions

Flask_Bower-1.3.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

Flask_Bower-1.3.0-py2-none-any.whl (7.6 kB view details)

Uploaded Python 2

File details

Details for the file Flask-Bower-1.3.0.tar.gz.

File metadata

  • Download URL: Flask-Bower-1.3.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Flask-Bower-1.3.0.tar.gz
Algorithm Hash digest
SHA256 3b884a80d872f7cfaf5b351aa90af4afaadc02588a764e1071de56963d6cbcb8
MD5 2d830b187d83c009abac0379431a46b2
BLAKE2b-256 47321733dc8b74efd05a609546c322c9ad74c4441ec79652e3e19986f7fd720d

See more details on using hashes here.

File details

Details for the file Flask_Bower-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for Flask_Bower-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00842ee71667a34c82ef9688df3e50241f367022ccd64675967e5f3c2282c2a0
MD5 81a8265d45e384e501539c4830c27415
BLAKE2b-256 616a8600081f0bf5dda08ab677f9a57ca871060cc51df047ea2826cdd2a673b3

See more details on using hashes here.

File details

Details for the file Flask_Bower-1.3.0-py2-none-any.whl.

File metadata

File hashes

Hashes for Flask_Bower-1.3.0-py2-none-any.whl
Algorithm Hash digest
SHA256 16b5919e4b95f736403f3b843d0cbe06ff30493a26524ef85522be1922b1bc5b
MD5 ab1f428541a5c8d753240aa8dce3b1da
BLAKE2b-256 4114231820b32859762e2a7f5d66dac8287426f9597c8f17addaf74dc2348626

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page