Use Flask-Assets to compile multiple Javascript files to one

This commit is contained in:
Patrick Jentsch 2021-01-18 13:22:00 +01:00
parent 6bc5e5f7b1
commit e0bbc517e9
4 changed files with 25 additions and 11 deletions

4
.gitignore vendored
View File

@ -3,6 +3,10 @@
# C extensions
*.so
# Flask-Assets files
.webassets-cache
*.compiled.js
# Docker related files
docker-compose.override.yml
db

View File

@ -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)

View File

@ -254,17 +254,23 @@
<script src="{{ url_for('static', filename='js/list.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/socket.io.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/main.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/RessourceDisplays/RessourceDisplay.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/RessourceDisplays/CorpusDisplay.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/RessourceDisplays/JobDisplay.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/RessourceLists/RessourceList.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/RessourceLists/CorpusList.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/RessourceLists/CorpusFileList.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/RessourceLists/JobList.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/RessourceLists/JobInputList.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/RessourceLists/JobResultList.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/RessourceLists/QueryResultList.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/RessourceLists/UserList.js') }}"></script>
{% assets output="js/nopaque/RessourceDisplays.compiled.js",
"js/nopaque/RessourceDisplays/RessourceDisplay.js",
"js/nopaque/RessourceDisplays/CorpusDisplay.js",
"js/nopaque/RessourceDisplays/JobDisplay.js" %}
<script src="{{ ASSET_URL }}"></script>
{% 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" %}
<script src="{{ ASSET_URL }}"></script>
{% endassets %}
<script>
// Disable all option elements with no value
for (let optionElement of document.querySelectorAll('option[value=""]')) {optionElement.disabled = true;}

View File

@ -2,6 +2,7 @@ cqi
docker
eventlet
Flask
Flask-Assets
Flask-Login
Flask-Mail
Flask-Migrate