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

Multiple and aliased publicDirs #16138

Open
4 tasks done
danielroe opened this issue Mar 11, 2024 · 4 comments
Open
4 tasks done

Multiple and aliased publicDirs #16138

danielroe opened this issue Mar 11, 2024 · 4 comments
Labels
p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)

Comments

@danielroe
Copy link
Contributor

Description

Currently, Vite supports a single publicDir. However, there are situations where we might want to merge multiple public directories. For example, in Nuxt we support an arbitrary number of public directories, each with a possible prefix (e.g. /foo points to /some/dir)

We can implement this within Nuxt itself (e.g. nuxt/nuxt#26163) but we obviously lose out on some of the cool features Vite has, like rendering relative URLs, and in general the entire asset pipeline.

Suggested solution

publicDir could also accept an array of strings or objects of { dir: string, prefix: string } (to support alias).

Alternative

No response

Additional context

No response

Validations

@patak-dev patak-dev added p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) and removed enhancement: pending triage labels Mar 11, 2024
@patak-dev
Copy link
Member

I took a look at this one thinking it will be easy to implement, but if we go with publicDir: string | string[] | false it will be a breaking change. I did a code search and there are a lot of plugins and downstream projects expecting config.publicDir to be a string.
So we could only do this in a major and still there, it may be too big of a change.
We could add another option like config.extraPublicDirs that at least won't be breaking, but it will be hard to push the ecosystem to properly support it (there will be silent fails in this case).
Maybe others have a better idea of how to tackle this. For now, it may not be a bad idea that you move forward with the PR you already have for Nuxt and we keep this issue open and gather more feedback. If there are other frameworks and projects in need of this feature, we could make a stronger case.

@bluwy
Copy link
Member

bluwy commented Mar 12, 2024

This looks similar to #3428, which proposes support for snowpack mounts. I think it's an interesting idea, but I've not hit many cases that requires it (including for Astro and SvelteKit), and a single public directory has served well. I also think Nuxt can go ahead with its PR at the meantime. Following #3428, there only seems a few users who wanted it.

@zhixiaotong
Copy link

In the application with Monorepo, I need to flexibly combine various modules to generate the application. Although putting the static resources of all modules in a shared package is a solution, it will cause shared to maintain many assets that do not need to exist originally. I hope there is a way to implement different sub-applications to maintain their own assets. This problem can be solved by passing a static resource directory array during dev or build. If publicDir supports arrays, it is the solution I want.

@nguyenbatranvan
Copy link

nguyenbatranvan commented Oct 30, 2024

I encountered this problem while working with monorepo. So I created a plugin for it. You can check out my library
vite-multiple-assets
Document for it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
Development

No branches or pull requests

5 participants