Closed boboldehampsink closed 9 months ago
So interestingly, at least in theory, the logic is already in there to do this:
public function asset(string $path, bool $public = false): string
{
if ($this->devServerRunning()) {
return $this->devServerAsset($path);
}
if ($public) {
return $this->publicAsset($path);
}
return $this->manifestAsset($path);
}
ref: https://github.com/nystudio107/craft-plugin-vite/blob/develop-v4/src/services/ViteService.php#L310
Why it isn't working as expected, I'm not sure.
Okay I misunderstood the issue on the initial read. The actual issue is that PHP needs to pull from the internal Docker network to do what you want.
Added in: https://github.com/nystudio107/craft-plugin-vite/commit/bf8df08f97bb4263753f555a364210b0efc7e56a & https://github.com/nystudio107/craft-plugin-vite/commit/ce9424a33f844d6fcc1bd1caf5fe565b3c0dd651 & https://github.com/nystudio107/craft-plugin-vite/commit/ed4c7d026da83ea507e9cc7d9432dbb79ccf8866
Craft CMS 3:
You can try it now by setting your semver in your composer.json
to look like this:
"nystudio107/craft-plugin-vite": "dev-develop as 1.0.33”,
Then do a composer clear-cache && composer update
…..
Craft CMS 4:
You can try it now by setting your semver in your composer.json
to look like this:
"nystudio107/craft-plugin-vite": "dev-develop-v4 as 4.0.9”,
Then do a composer clear-cache && composer update
…..
Craft CMS 5:
You can try it now by setting your semver in your composer.json
to look like this:
"nystudio107/craft-plugin-vite": "dev-develop-v5 as 5.0.0-beta.2”,
Then do a composer clear-cache && composer update
@khalwat correct - but only when using .inline
! Because just outputting the .asset
url in the source will forward it to the browser, which doesn't know the internal server url...
Right. Try the changes I pushed @boboldehampsink
Works, thanks!
I'm using Docker, where I have a web container and a separate vite container.
{% set logoPath = craft.vite.asset('/src/assets/img/svg/brand-logo.svg') %}
returnshttp://localhost:3000/src/assets/img/svg/brand-logo.svg
, which is fine for public use. But when I want to do this:{{ craft.vite.inline(logoPath) }}
It fails because we're still in Docker, and it doesn't know localhost:3000 - it needs vite:3000 (the internal dev server url als you call it)
My workaround for now is:
{{ craft.vite.inline(logoPath|replace('localhost', 'vite')) }}
But it would be nice to have an option for example on
craft.vite.asset
to use the internal dev server url