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

public assets v4 #9

Merged
merged 1 commit into from Jun 29, 2022
Merged

Conversation

samuelbirch
Copy link
Contributor

adds a boolean as a second param to the craft.vite.asset('url', true) so that assets in the vite public folder can be referenced correctly.

@samuelbirch samuelbirch changed the title public assets public assets v4 Jun 29, 2022
@khalwat
Copy link
Contributor

khalwat commented Jun 29, 2022

Is this something that isn't working correctly currently? Shouldn't anything in /public be served by the dev server if you're running it?

@samuelbirch
Copy link
Contributor Author

samuelbirch commented Jun 29, 2022

If i have assets that are referenced in the css or js then it all works fine.

Its when i want to use a public asset, the dev server is working but not when its been built as the asset is not in the manifest.

This tweak doesn't use the manifest and return the path prefixed with the destination folder

@khalwat
Copy link
Contributor

khalwat commented Jun 29, 2022

Ah I see. They are solving this in Vite 3 via this PR: vitejs/vite#6649 (comment)

Are you able to wait until then, or...?

@samuelbirch
Copy link
Contributor Author

Yes i could wait until then (although don't know when "then" is?)

I'm assuming that PR is about being able to add assets to the manifest (outside of js/css), but wouldn't we still have the same issue with public assets (that we don't want hashed) not being able to correctly reference?

@khalwat
Copy link
Contributor

khalwat commented Jun 29, 2022

Ah yes, you're right on both fronts. How about this for an idea -- since they have hard-coded public what if instead of a flag, we looked for public in the first segment of the incoming URL, and did it automagically?

@samuelbirch
Copy link
Contributor Author

"public" can be configured using the "publicDir" property, I have it set to "/src/assets"

instead of a flag, we could add another function: craft.vite.publicAsset('url'). I thought a flag might be cleaner.

@khalwat
Copy link
Contributor

khalwat commented Jun 29, 2022

Roger that. Will merge it in and update the docs -- I'm assuming this works with the devServer as well as in production?

@samuelbirch
Copy link
Contributor Author

samuelbirch commented Jun 29, 2022

yes it works with both.

@khalwat khalwat merged commit 3d6bec1 into nystudio107:develop-v4 Jun 29, 2022
@khalwat
Copy link
Contributor

khalwat commented Jun 29, 2022

Thx for the PR!

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.

None yet

2 participants