-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add customizable app_client_class config value #138
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a very good idea to let people change how to load and parse the manifest file as it changes a lot between Vite versions and project configurations.
Maybe can you add a short paragraph in the README to let people know that and I will be happy to approve this change.
Thanks !
@@ -212,6 +222,8 @@ class DjangoViteAppClient: | |||
DjangoViteConfig provides the arguments for the client. | |||
""" | |||
|
|||
ManifestClient = ManifestClient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems a bit redundant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defining the ManifestClient as a class variable allows you to create a subclassed DjangoViteAppClient with a separate subclassed ManifestClient. You can look at the test_custom_app_client_class
for an example. If we didn't do this, then we'd have no way to overwrite the logic of the ManifestClient without doing module-level monkeypatching.
Thinking this through, we should probably also add other dependency classes like TagGenerator as class variables as well, to allow them to be easily extensible.
This worked really well to prove out that we could move from webpack/django-webpack-loader to vite/django-vite. It was smooth sailing with the As an idea for simplification, if |
Any chance we can move this forward? We're in the process on migrating from django-webpack to django-vite and this would be a big help in keeping the two processes as similar as possible (we upload our stats file to S3 and then have the Django build grab that file, rather than injecting it into the django static dir at build time). |
Sure, let me look at picking this back up. 👍
Possibly. But there could be a lot of variety in the distinct ways that people fetch assets remotely. I think it would be most flexible to allow people to use a custom class. But if there end up being common recipes that work well, we can commit them to the library. |
66bf0b3
to
2e9d20d
Compare
Okay, this feature is ready to go. I added some documentation about "Loading assets from a CDN". One of the upsides of this PR is that it will let people modify the most of internals of django-vite however they'd like by providing a custom
I'm still open to this idea in theory, but I think it be difficult to implement universally if your manifest is not publicly accessible. Different providers (like S3) will all have different clients/authentication schemes. But if someone finds a simple way to implement this feature without requiring everyone to write a custom |
Here's a solution that could give people the freedom to pull manifest.json files from any external location.
This was heavily inspired by a similar feature in django-webpack-loader: django-webpack/django-webpack-loader#210. It's addressing the same user issue that we have, some people wanted to load their manifests from external urls. Instead of supporting every bespoke source that a manifest.json could be generated from, django-webpack-loader added the ability for users to plug in their own loader classes that had their own retrieval mechanisms.
This PR gives an example of that in
test_custom_app_client.py
. (Admittedly, this implementation is a little messier than django-webpack-loader, since we have to go through a second static class.)There are probably ways to make this cleaner. I'm open to any suggestions.
Related: #105