Django + Vue with multiple apps

1.3k Views Asked by At

There are plenty of tutorials and helpful posts how to use Django and Vue properly (in various options) all over the Internet. But I didn't find a single one who describes how to create a Django application which consists of more than one app, each having it's own part of the Vue frontend.

I am creating a Django application with a Vue frontend, and it will have a lot of apps that can be plugged into the main system very easily (using a custom framework). But this only is the backend. I'd like to enable each Django app for having a "plugin" part of the frontend as well: e.g. a set of Vue components that are rendered "dynamically" in the frontend when this app is added in INSTALLED_APPS.

  • How can I provide "plugin hooks" in Vue to load those components? All the things I have seen (dynamic/lazy component loading with webpack using webpack-loader, etc.) is not what I want. It only describes how to load a component that is predefined later in the http request timeline.

  • How am I supposed to "merge" all the components? Can I simply create components in static folders and let ./manage.py collectstatic do the magic?

It doesn't matter if the application is a SPA or maybe I have to use Django templates (with Vue components included) - both would be a viable method.

Maybe this even is a webpack question and should be: How do I bring Vue (or React, etc) to collect its sources from different subdirectories like foo_app/static/, blah_app/static/, bar_app/static - is there a way to tell Vue/Webpack/etc to search in myproject/*/static for Vue components to merge? And can I include "all components" (dynamical amount) than in another component, which is needed for such a system?

Can anyone enlighten me here - is that completely impossible? Or am I thinking in the wrong direction?

Thanks.

1

There are 1 best solutions below

7
On

I have a couple of VueJS apps in my django site and I'm planning to add more. I bundle them with webpack with the help of django-webpack-loader. https://github.com/owais/django-webpack-loader