Skip to content
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

Support public folder output #145

Open
scobenes opened this issue Aug 8, 2024 · 1 comment
Open

Support public folder output #145

scobenes opened this issue Aug 8, 2024 · 1 comment

Comments

@scobenes
Copy link

scobenes commented Aug 8, 2024

So there is a public folder option in vite build that does not create any entries, but you can still reference entries off of the root. https://vitejs.dev/guide/assets#the-public-directory

In my template I still want to reference these items by using the vite_asset_url function.

<link rel="apple-touch-icon" href="{{ vite_asset_url('site-images/site/apple-touch-icon.png') }}">

So my way around this was to add a configuration of public_folder_passthrough. I don't know a better name or if this is even the correct path, but I updated the ManifestClient.get() method to make a pass through entry if it fails to find it in the manifest.json.

        if path not in self._entries:
            if self._config.public_folder_passthrough:
                return ManifestEntry(
                    file=path,
                    src=path,
                    isEntry=True,
                )
            else:
                raise DjangoViteAssetNotFoundError(
                    f"Cannot find {path} for app={self.app_name} in Vite manifest at "
                    f"{self.manifest_path}"
                )

I am not sure if there is a better way, but this works exactly as expected once I added the passthrough for the public assets

@tchappui
Copy link

tchappui commented Dec 1, 2024

I bypass this problem by adding both the dist and public folders in STATICFILES_DIRS. In my templates, I always reference the files that are in public using the static tag rather than using the vite_asset_url tag. Naturally, if Django-Vite managed the files correctly in a public directory, it would be great. This would avoid asymmetry between the files associated with the frontend.

However, this has the advantage of being a simple solution that does not involve any direct modification of Django-Vite. Maybe I'm missing, however, a border effect that is likely to pose a problem.

Kind regards, Thierry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants