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

Use public/ for outDir by default #67

Closed
wants to merge 1 commit into from
Closed

Use public/ for outDir by default #67

wants to merge 1 commit into from

Conversation

kabouzeid
Copy link
Contributor

This is more similar to what Laravel Mix does. By setting emptyOutDir = false, the build dir is no longer cleared by Vite.

Also I've ran into problems with public/build/assets because some Vite plugins assume that files in outDir/assets are served from the /assets route.

@kabouzeid kabouzeid changed the title Use public/ for outDir by default. Disable emptyOutDir. Use public/ for outDir by default. Disable emptyOutDir. Apr 13, 2021
@kabouzeid kabouzeid changed the title Use public/ for outDir by default. Disable emptyOutDir. Use public/ for outDir by default. (Possible by setting emptyOutDir = false). Apr 13, 2021
@kabouzeid kabouzeid changed the title Use public/ for outDir by default. (Possible by setting emptyOutDir = false). Use public/ for outDir by default Apr 13, 2021
@innocenzi
Copy link
Owner

I didn't know about emptyOutDir, but I'm quite happy with the current build directory default. I personally dislike having assets generated right into public. Could you tell me more about the exact issues you encountered so I can see if it's worth the change? I'd love some links to the plugins you're talking about as well. Thank you!

@kabouzeid
Copy link
Contributor Author

I'm using a Vite plugin for bundling Rust WebAssembly.
The .wasm asset is placed in the asset dir (see: https://github.com/lencx/vite-plugin-rsw/blob/a3e237ca8454bce9b5a96fef09419bb888cc3831/src/index.ts#L47) and later fetched from / (see: same file, line 59).
Not sure whether this plugin does it the "right" way.

But at least it shows that public/ is a sensible default for the outDir since it matches the default behavior of Vite and the default behavior of Laravel Mix. Also it's still possible to achieve the current result :)

@kabouzeid
Copy link
Contributor Author

After looking at it again, I think the plugin I mentioned above is doing it wrong and should use something like base/file instead of /file.

@innocenzi
Copy link
Owner

After looking at it again, I think the plugin I mentioned above is doing it wrong and should use something like base/file instead of /file.

You're right, the plugin should use config?.build?.outDir in addition to assetsDir, since the latter is relative to the former.

But at least it shows that public/ is a sensible default for the outDir since it matches the default behavior of Vite and the default behavior of Laravel Mix. Also it's still possible to achieve the current result :)

I think you're half-right: while having consistency is good, sometimes the conventions are not perfect. Like I said, I'm really not a fan of having everything in public (as a matter of fact, before this commit, there was no way to not clean the outDir).

If you personally prefer it, you can change build_path in vite.php and add build.emptyOutDir to your vite.config.ts.

Since your specific issue is fixable, and since I'd rather avoid the breaking change, I'll close the PR. Hope you're okay with that. Good luck with your project!

@innocenzi innocenzi closed this Apr 13, 2021
@kabouzeid
Copy link
Contributor Author

Sure, I completely understand. In the meantime I've fixed this upstream, thanks :)
If someone with a similar problem comes across this, here is the relevant PR: rwasm/vite-plugin-rsw#4

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

Successfully merging this pull request may close these issues.

2 participants