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

No way to combine craft.vite.asset with craft.vite.inline in Docker #22

Closed
boboldehampsink opened this issue Jan 18, 2024 · 7 comments
Closed
Labels
bug Something isn't working

Comments

@boboldehampsink
Copy link

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') %} returns http://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

@khalwat
Copy link
Contributor

khalwat commented Jan 21, 2024

Similar to: nystudio107/craft-vite#72

@khalwat
Copy link
Contributor

khalwat commented Jan 21, 2024

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.

@khalwat
Copy link
Contributor

khalwat commented Jan 22, 2024

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.

@khalwat khalwat closed this as completed Jan 22, 2024
khalwat added a commit that referenced this issue Jan 22, 2024
…d will try to use the `devServerInternal` URL first, falling back on the `devServerPublic` so that `craft.vite.inline()` can pull from the `devServer` if it is running ([#22](#22))
khalwat added a commit that referenced this issue Jan 22, 2024
…d will try to use the `devServerInternal` URL first, falling back on the `devServerPublic` so that `craft.vite.inline()` can pull from the `devServer` if it is running ([#22](#22))
khalwat added a commit that referenced this issue Jan 22, 2024
…d will try to use the `devServerInternal` URL first, falling back on the `devServerPublic` so that `craft.vite.inline()` can pull from the `devServer` if it is running ([#22](#22))
@khalwat
Copy link
Contributor

khalwat commented Jan 22, 2024

Added in: bf8df08 & ce9424a & ed4c7d0

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

@boboldehampsink
Copy link
Author

@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...

@khalwat
Copy link
Contributor

khalwat commented Jan 22, 2024

Right. Try the changes I pushed @boboldehampsink

@boboldehampsink
Copy link
Author

Works, thanks!

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