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

inline() function not working with relative local path #55

Closed
jrrdnx opened this issue Jan 13, 2023 · 2 comments
Closed

inline() function not working with relative local path #55

jrrdnx opened this issue Jan 13, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@jrrdnx
Copy link

jrrdnx commented Jan 13, 2023

The craft.vite.inline() function doesn't output the contents of my CSS file when the serverPublic setting in the config uses only a relative local path and doesn't include the base URL.

Essentially, this line:

{{ craft.vite.inline(craft.vite.entry('src/scss/critical.scss')) }}

works ONLY when

'serverPublic' => App::env('BASE_URL') . '/dist/',

but NOT when

'serverPublic' => '/dist/',

craft.vite.entry('src/scss/critical.scss') outputs the correct URL in both scenarios, so it's just the inline() function that doesn't seem to be working in the latter.

There is an error output to the web log, but it's the same in both scenarios as well:

2023-01-13 16:43:03 [web.ERROR] [nystudio107\pluginvite\helpers\FileHelper::fetchResponse] cURL error 7: Failed to connect to localhost port 5173 after 1274 ms: Couldn't connect to server (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://localhost:5173/__vite_ping {"memory":1923336} 

Not a critical issue, but we would prefer to use relative paths for these resources.

Versions

  • Plugin version: 4.0.4
  • Craft version: 4.3.6.1
@jrrdnx jrrdnx added the bug Something isn't working label Jan 13, 2023
@khalwat
Copy link
Contributor

khalwat commented Jan 25, 2023

So at least for now, I think you're going to need to use absolute paths. If you want to do a PR for this feature though, I'm open to it!

@khalwat khalwat closed this as completed Jan 25, 2023
@jrrdnx
Copy link
Author

jrrdnx commented Jan 28, 2023

I looked into this, but I wasn't quite sure how to build this in while ensuring backwards compatibility. I did track it down to this file in craft-plugin-vite. The URL is web-relative and not server-relative so I was able to fix it in my case by prefixing it with @webroot:

{{ craft.vite.inline('@webroot' ~ craft.vite.entry('src/scss/critical.scss')) }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants