diff --git a/assets/en/vite.texy b/assets/en/vite.texy index 781e62016a..d561b1b3dd 100644 --- a/assets/en/vite.texy +++ b/assets/en/vite.texy @@ -288,6 +288,59 @@ export default defineConfig({ Actually, even in this case, you need to configure CORS because the dev server runs on the same hostname but on a different port. However, in this case, CORS is automatically configured by the Nette Vite plugin. +**Option 3: Run Vite inside a container** + +If you run Vite inside a container, you will need to set the server host option to `true` or `0.0.0.0`. The Nette Vite plugin will automatically generate the dev server url and CORS origin using `localhost`. + +Optionally, you can set the plugin host option to use another domain. Check out the [#Docker Development] section for more information. + +```js +export default defineConfig({ + // ... other config ... + + plugins: [ + nette({ + host: 'myapp.local' // same as your PHP app + }) + ], + server: { + host: true, + }, +}); +``` + + +Docker Development +------------------ + +If you run your application inside Docker containers during development, you should [expose |https://docs.docker.com/get-started/docker-concepts/running-containers/publishing-ports/] the Vite port. + +It is also necessary to configure Vite in a way that allows you to make requests to the dev server from your host machine: + +```js +export default defineConfig({ + // ... other config ... + + plugins: [ + nette({ + host: 'myapp.local' // same as your PHP app - will be used for the CORS origin, allowed hosts and dev server url + }) + ], + server: { + host: '0.0.0.0', // or true, necessary to properly resolve the dev server and cannot be set to a custom domain + port: 5173, // same as the port you exposed from your Docker container + strictPort: true, // Vite should not start if the port is not available + watch: { + usePolling: true, // set this if Vite does not pick up on file changes (may consume more resources) + }, + }, +}); +``` + +The allowed hosts and CORS server options are handled by the Nette Vite plugin for you. Ofcourse, you are welcome to configure them manually. + +If you develop on a domain other than `localhost`, make sure to include it in the host option of the Nette Vite plugin. Otherwise you will run into [CORS issues#Working on Different Domains]. + HTTPS Development -----------------