Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[1.x] Add remote IDE support #305

Draft
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Draft

[1.x] Add remote IDE support #305

wants to merge 1 commit into from

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Oct 17, 2024

Adds some environment variables to allow cloud IDE to configure the Vite plugin so that things just work out of the box.

There are some current limitations that cloud IDE environments may hit.

The first is that Vite will likely need to run listening on all interfaces. Although this can be manually achieved via npm run dev -- --host, I have added an environment value that allows this to be the default behaviour.

export VITE_HOST=0.0.0.0

With the value in the environment, Vite will automatically listen on all interfaces.

The next hurdle that cloud IDEs may need to customise the format of the public facing dev server URL. This is the URL that is written to the hot file, rendered in Laravel templates, and also transformed in the JavaScript and CSS files when pointing to other resources.

The default format of this URL is {scheme}://{host}:{port}. This results in the standard Vite URL we see locally: http://[::]:5173.

Cloud IDEs may need to have the Vite dev server listening on HTTP while the publicaly rendered URL needs to be HTTPS. Additionally, to format of the publicaly exposed URL may need to be different. For example, one cloud IDE has the format https://{port}-{host}.

This PR introduces a new environment variable to control the publicly exposed dev server URL. The environment variable may contain hard coded information...

export VITE_EXPOSED_DEV_SERVER_URL=https://example.com:5173

However, as some of these values are dynamic, e.g., the port, or configurable, e.g., the host, the environment variable may also contain placeholders that will be replaced with the actual values.

{scheme}, {host}, and {port} are the supported placeholders, e.g.,

export VITE_EXPOSED_DEV_SERVER_URL={scheme}://{port}-{host}

You can mix and match these as needed, for example, if you only needed to retrieve the port from Vite:

export VITE_EXPOSED_DEV_SERVER_URL=https://{port}-my-custom-host.com

@timacdonald timacdonald marked this pull request as draft October 17, 2024 04:47
@nurdism
Copy link
Contributor

nurdism commented Oct 30, 2024

why just make the hot file url configurable? combined with vites server config, it lets you do all of this.

@jradtilbrook
Copy link

👏 Exactly what I'm looking for to be able to run a "remote" IDE but its just a tailscale serve.

I'd love if this could be pushed through, but I think the changes are not backwards compatible are they?

@jradtilbrook
Copy link

Works like a charm, except your original description has a typo @timacdonald. The env var you have used in code is LARAVEL_VITE_EXPOSED_DEV_SERVER_URL, note the LARAVEL_ at the beginning.

Would love for this to be released! FWIW, without changing my vite.config.js from the default from laravel new everything remained working. But I'm not sure if other configurations from users might cause issues.

@@ -434,7 +436,9 @@ function resolveDevServerUrl(address: AddressInfo, config: ResolvedConfig, userC
const configHmrClientPort = typeof config.server.hmr === 'object' ? config.server.hmr.clientPort : null
const port = configHmrClientPort ?? address.port

return `${protocol}://${host}:${port}`
return format.replace('{protocol}', protocol)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually another typo: your original description used {scheme}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants