# Deploying while Vite dev server is active causes broken URLs due to public/hot file existing

**URL:** https://discourse.roots.io/t/deploying-while-vite-dev-server-is-active-causes-broken-urls-due-to-public-hot-file-existing/29601
**Category:** sage
**Tags:** vite, sage11
**Created:** 2025-05-12T09:00:54Z
**Posts:** 8

## Post 1 by @aitor — 2025-05-12T09:00:54Z

I’m using the full Roots stack (Trellis, Bedrock, Sage 11 with Vite). Everything works fine locally, but I’ve run into a problem when deploying.

If I have the dev server running (`npm run dev`) at the time of deployment, the file `web/app/themes/sage/public/hot` is present in my local project and gets synced to the production server via Trellis (`synchronize` task).

This file causes Sage to load assets from `http://[::1]:5173`, which completely breaks the site in production: I get CORS errors, fonts fail to load, and JS is blocked.

I know this is easy to fix (e.g., `--exclude=hot` in the `synchronize` task or removing the file before deploying), but I wonder:

- Should this be mentioned in the official documentation?
- Could `hot` be excluded by default in the example `build-before.yml`?
- Are there any best practices for preventing this, especially on teams with multiple developers?

Any thoughts or recommendations are very welcome. Thanks!

---

## Post 2 by @dsemblano — 2025-05-12T13:27:28Z

My workaround was adding the `/public/hot` path to `.gitignore` in the Sage theme folder.

---

## Post 3 by @aitor — 2025-05-12T13:38:43Z

AFAIK, this won’t work with Trellis, since it uses Ansible’s `synchronize` module (rsync) to copy files directly from the local filesystem — not from Git. So even if `public/hot` is in `.gitignore`, it will still be copied to the server if it exists locally.

---

## Post 4 by @ben — 2025-05-12T13:55:56Z

> [@aitor](#):
>
> Could `hot` be excluded by default in the example `build-before.yml`?

We could, but there’s potentially more issues that could occur when deploying the theme when the dev server is running besides just the `public/hot` file existing

> [@aitor](#):
>
> Are there any best practices for preventing this, especially on teams with multiple developers?

Don’t deploy from your local machine. Some resources to look at:

- [https://roots.io/trellis/docs/deploy-with-github-actions/](https://roots.io/trellis/docs/deploy-with-github-actions/)
- [https://github.com/roots/setup-trellis-cli](https://github.com/roots/setup-trellis-cli)
- [https://github.com/MWDelaney/trellis-github-deployment](https://github.com/MWDelaney/trellis-github-deployment)

---

## Post 5 by @aitor — 2025-05-15T10:57:32Z

I’ve been setting up automated deployment with GitHub Actions over the past few days, and I ended up writing a guide to keep track of everything. Thought I’d share it here in case it’s useful to someone—or if anyone wants to chime in with improvements.

> <https://gist.github.com/aitormendez/c0c68510e2c91c784deb07ae55b0e8f6>

---

## Post 6 by @rguttersohn — 2025-07-29T18:52:49Z

I wound up adding a couple of scripts that turn off my dev server before deploying:

```
"predeploy": "npm run stop-vite && npm run clean-hot",
"stop-vite": "pkill -f vite || true",
 "clean-hot": "rm -f public/build/hot",
```

then added this in build-before.yml:

```
- name: Pre-deploy cleanup (stop Vite, remove hot)
  command: npm run predeploy
  delegate_to: localhost
  args:
    chdir: "{{ project_local_path }}/web/app/themes/<theme>"
```

---

## Post 7 by @artshostak — 2025-11-14T18:13:00Z

Thanks this is really helpful, following your lead — what’s stopping us from simply doing this in the `build-before.yml` file?

```
# After: Compile assets
# Add to make sure Vite's dev "hot" file never gets deployed
- name: Remove Vite hot file from prod
  file:
    path: "{{ item }}"
    state: absent
  loop:
    - "{{ project_local_path }}/web/app/themes/rb/public/hot"
    - "{{ project_local_path }}/web/app/themes/rb/public/build/hot"
  delegate_to: localhost
```

---

## Post 8 by @ben — 2025-11-14T21:47:53Z

See my post above — don’t deploy from your local machine.
