I've done this in the past but I'm completely forgetting how I did it. I'm developing a flask server that contains multiple apps with the static files bundled together but I want the js/css files in each app's static folder to be used only by the routes defined within that app's init.py file.
Lets assume I have an appA and appB:
app
- static // this contains my common js/css files
- apps
- appA
- __init__.py
- static // appA's js/css files
- appB
- __init__.py
- static // appB's js/css files
And I go to "localhost:8000:/appA" (assuming its a route i've defined). In its js file I have
$(document).ready(function(params) {
console.log('appA ready');
});
And if I go to "localhost:8000/appB" and it has in its js file
$(document).ready(function(params) {
console.log('appB ready');
});
No matter which route I run I will see "appA ready" and "appB ready" printed in the console. Now I know that this makes sense. I've bundled and minified them together after all. But for the life of me I know I've used bundles in the past but was able to single out which app used what static file.
The point is to use a base static directory for common stuff and the app's static directory for app-specific things.
I have my assets configured thusly
from app.apps.appA import appA
from app.apps.appA import appA_js, appA_css
from app.apps.appB import appB
from app.apps.appB import appB_js, appB_css
flask_app.register_blueprint(appA)
flask_app.register_blueprint(appB)
globals_js = ('js/utils/jquery-3.4.1.min.js',
'js/utils/socket.io.js',
'js/utils/*.js')
globals_css = ('css/utils/common.css',
'css/utils/*.css')
assets = Environment(flask_app)
bundle_globals_js = Bundle(*globals_js + appA_js + appB_js, filters='jsmin', output='dist/local_js.js')
bundle_globals_css = Bundle(*globals_css + appA_css + appB_css, filters='cssmin', output='dist/local_css.css')
assets.register('base_js', bundle_globals_js)
assets.register('base_css', bundle_globals_css)
I feel like there's something about my asset bundle configuration that is wrong. Either that or it's how I'm importing the files in my html.
<head>
{% assets "base_js" %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}
{% assets "base_css" %}
<link rel="stylesheet" href="{{ ASSET_URL }}"/>
{% endassets %}
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{{title}}</title>
</head>
This is the header code being used by each specific html file appA and appB has. There may simply be a fundamental misunderstanding here about how bundles are used. I just want to specify a common static directory but be able to have my apps use their own js/css files in combination with those base files.
Could someone point me in the right direction?
Thanks!