Skip to content

New Vite plugin option and behavior #1079

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions assets/en/vite.texy
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------
Expand Down