Skip to content

Support public folder output #145

@scobenes

Description

@scobenes

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions