From e0bbc517e99937f07f0c44af3d201d475938ca99 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Mon, 18 Jan 2021 13:22:00 +0100 Subject: [PATCH] Use Flask-Assets to compile multiple Javascript files to one --- .gitignore | 4 ++++ web/app/__init__.py | 3 +++ web/app/templates/nopaque.html.j2 | 28 +++++++++++++++++----------- web/requirements.txt | 1 + 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index de6e4247..9d5ca616 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,10 @@ # C extensions *.so +# Flask-Assets files +.webassets-cache +*.compiled.js + # Docker related files docker-compose.override.yml db diff --git a/web/app/__init__.py b/web/app/__init__.py index 9a399ddc..75be4213 100644 --- a/web/app/__init__.py +++ b/web/app/__init__.py @@ -5,8 +5,10 @@ from flask_mail import Mail from flask_paranoid import Paranoid from flask_socketio import SocketIO from flask_sqlalchemy import SQLAlchemy +import flask_assets +assets = flask_assets.Environment() db = SQLAlchemy() login_manager = LoginManager() login_manager.login_view = 'auth.login' @@ -20,6 +22,7 @@ def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) + assets.init_app(app) config[config_name].init_app(app) db.init_app(app) login_manager.init_app(app) diff --git a/web/app/templates/nopaque.html.j2 b/web/app/templates/nopaque.html.j2 index 3e7978bc..f53ad189 100644 --- a/web/app/templates/nopaque.html.j2 +++ b/web/app/templates/nopaque.html.j2 @@ -254,17 +254,23 @@ - - - - - - - - - - - +{% assets output="js/nopaque/RessourceDisplays.compiled.js", + "js/nopaque/RessourceDisplays/RessourceDisplay.js", + "js/nopaque/RessourceDisplays/CorpusDisplay.js", + "js/nopaque/RessourceDisplays/JobDisplay.js" %} + +{% endassets %} +{% assets output="js/nopaque/RessourceLists.compiled.js", + "js/nopaque/RessourceLists/RessourceList.js", + "js/nopaque/RessourceLists/CorpusList.js", + "js/nopaque/RessourceLists/CorpusFileList.js", + "js/nopaque/RessourceLists/JobList.js", + "js/nopaque/RessourceLists/JobInputList.js", + "js/nopaque/RessourceLists/JobResultList.js", + "js/nopaque/RessourceLists/QueryResultList.js", + "js/nopaque/RessourceLists/UserList.js" %} + +{% endassets %}