bhbs / viject

A tool for migrating your React app from react-scripts (Create React App) to Vite
https://www.npmjs.com/package/viject
MIT License
122 stars 2 forks source link

Cannot activate host configuration from cli as Vite does #50

Open rangzen opened 1 month ago

rangzen commented 1 month ago

Describe the bug Once viject passed, can't activate listening on network with --host.

To Reproduce Steps to reproduce the behavior:

  1. Create a CRA
  2. Run it, you can access through localhost and from the network (192.168.0.0/24)
  3. Run viject
  4. Can't access from the network

Steps to reproduce the behavior:

  1. Create a Vite app
  2. Run it, you can access through localhost and from the network (192.168.0.0/24)

Expected behavior It seems that modifying vite.config.ts by adding server configuration in the defineConfig is not used. Same for --host variables from cli.

Workaround In devServerPlugin, change host to host: HOST || '0.0.0.0', to have the default value as opened is working. From the CLI, HOST='0.0.0.0' yarn dev is also working.

So, this is the normal behaviour with actual plugins, but if you check StackOverflow, Reddit, etc. some hints will not work. Maybe add some documentation or a comment in the vite.config.ts?

Anyway, awesome tool! Thank you!

bhbs commented 1 month ago

I found out that the CLI options weren't working because the plugin wasn't respecting the user configuration. I plan to address this issue for plugins other than devServer as well.

For now, I've released a quick fix that changes localhost to 0.0.0.0.

Thank you for reporting!!!