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

Include a 'devServerIsRunning' variable #10

Closed
stenvdb opened this issue Jun 30, 2021 · 3 comments
Closed

Include a 'devServerIsRunning' variable #10

stenvdb opened this issue Jun 30, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@stenvdb
Copy link

stenvdb commented Jun 30, 2021

As stated in your blog post, there is an issue with static assets being referenced in CSS for example (https://nystudio107.com/blog/using-vite-js-next-generation-frontend-tooling-with-craft-cms#vite-processed-assets). A workaround could be to include a <base> tag to manually set the base url for all relative links. The tag should be set to the dev server if it is running or the PRIMARY_SITE_URL if it is not.

Since this could cause other issues, the best way would be to do this manually in your templates. So what would help is a way to check if the vite dev server is running in your templates. Something like:

{% if craft.vite.devServerIsRunning %}
<base href="{{ alias('@viteBaseUrl') }}">
{% endif %}

If you would made sure that you're using absolute paths for all assets or urls in a site, then this would fix relative paths in CSS or JS.

@stenvdb stenvdb added the enhancement New feature or request label Jun 30, 2021
@khalwat
Copy link
Contributor

khalwat commented Jul 15, 2021

Good idea, I'll roll that in.

khalwat added a commit to nystudio107/craft-plugin-vite that referenced this issue Jul 15, 2021
…ine if the Vite dev server is running or not from your Twig templates (nystudio107/craft-vite#10)

Signed-off-by: Andrew Welch <[email protected]>
khalwat added a commit that referenced this issue Jul 15, 2021
…ine if the Vite dev server is running or not from your Twig templates (#10)

Signed-off-by: Andrew Welch <[email protected]>
@khalwat
Copy link
Contributor

khalwat commented Jul 15, 2021

Implemented in 1.0.13 -> https://github.com/nystudio107/craft-vite/releases/tag/1.0.13

@khalwat khalwat closed this as completed Jul 15, 2021
@khalwat
Copy link
Contributor

khalwat commented Jul 22, 2021

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

No branches or pull requests

2 participants