-
Notifications
You must be signed in to change notification settings - Fork 342
Description
I've used django-webpack-loader in a single-app django site, and it serves me well, thanks @owais !
Now I want to break up my django app into reusable apps which I'll add to INSTALLED_APPS.
These reusable apps will contain templates and javascript which I'd like to compile with webpack and reference in the templates with django-webpack-loader (as I currently do in my single-app site).
I want the templates and the js they contain to work out of the box when I add the app to the django site. I haven't found a way to do this yet.
Currently, the site's settings.py can contain something like:
WEBPACK_LOADER = {
'DEFAULT': {
'BUNDLE_DIR_NAME': 'bundles/',
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
},
'DASHBOARD': {
'BUNDLE_DIR_NAME': 'dashboard_bundles/',
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats-dashboard.json'),
}
}Great: I can define as many webpack projects as I want.
However, if one of my webpack projects is an INSTALLED_APP (as opposed to a subdirectory of BASE_DIR), I need to find the path to the app's webpack stats.
I can think of a hacky way to do this (importing the app's package, then looking up its __file__ attribute, then finding webpack-stats from there).
But that makes integrating the app that much harder, and introduces more coupling between the site and the app than is necessary.
Ideally, I'd like something analogous to django's collectstatic. I'd give webpack loader a STATS_FILE_DIR_NAME config telling the loader the name(s) of the directories containing webpack-stats.json files. The loader would collect webpack-stats from all app directories with that name.
So my webpack config in settings.py might look like:
WEBPACK_LOADER = {
'DEFAULT': {
'BUNDLE_DIR_NAME': 'bundles/',
'STATS_FILE_DIR_NAME': '/stats/'
},
}Then when using render_bundle in an html template, I could specify the app's name like so:
{% render_bundle DJANGO-APP-NAME BUNDLE-NAME %}
The template tag would look up the appropriate webpack-stats.json file for that app.
The author of this SO question seems to be looking for the same thing: https://stackoverflow.com/questions/52104733/django-vue-with-multiple-apps
Does anyone have thoughts on how to accomplish this ?