Media assets management for Invenio.

Invenio-Assets helps you with integration of webassets, installation of NPM packages, and process of collecting static files.


First create a Flask application:

>>> from flask import Flask
>>> app = Flask('myapp')

Next, initialize your extension:

>>> from invenio_assets import InvenioAssets
>>> assets = InvenioAssets(app)

During initialization two Flask extensions flask_webpackext.ext.FlaskWebpackExt and flask_collect.Collect are instantiated and configured.

Bundles specified in the entry point groups called invenio_assets.webpack are automatically registered by Invenio-Assets.

Using Flask-WebpackExt


The Flask-WebpackExt package provides a class flask_webpackext.bundle.WebpackBundle for declaring the needed assets and NPM dependencies of each one of your modules.

from flask_webpackext import WebpackBundle
bundle1 = WebpackBundle(
        'module1-app': './js/module1-app.js',
        'jquery': '^3.2.1'

The NPM dependencies defined in the bundles will be used to generate the package.json file.

Entry points loading

Invenio-Assets will automatically load bundles defined by the entry point group invenio_assets.webpack. Example:

    # ...
        'invenio_assets.webpack': [
            'mybundle = mypackage.bundles:mybundle',
        # ...
     # ...

Command-line interface

We can now build the assets:

$ flask webpack buildall

The command will copy all files from the src folder to the application instance folder designated for the Webpack project, download the npm packages and run Webpack to build our assets.

Alternatively, we can execute each build step separately with the following flask webpack commands:

  • create - Copy all sources to the working directory.
  • install - Run npm install command and download all dependencies.
  • build - Run npm run build.

Additionally if we have some static files we should collect them:

$ flask collect -v