fix(docker): start the dev server and pick up source changes
Two separate reasons the containerised dev workflow did not work: - CMD ran `npm run dev -- --host`. With no TTY under `docker compose up -d`, npm printed its banner and exited 0 immediately, so the dev server never started. Invoking vite directly keeps it running. - Vite's watcher receives no file-change events through a Docker Desktop bind mount, so it served stale modules indefinitely: edits appeared to have no effect and HMR never fired. Polling is opt-in via VITE_USE_POLLING, set by the compose file, so native dev is unaffected.
This commit is contained in:
1 parent
470a67607b
commit
be9420bf6d
2 files changed
+10
-1
No files matched your search
+4
-1
@@ -5,7 +5,10 @@ COPY package*.json ./
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
EXPOSE 5173
|
||||
CMD ["npm", "run", "dev", "--", "--host"]
|
||||
# Invoke vite directly rather than through `npm run`: under `docker compose
|
||||
# up -d` (no TTY, no stdin) the npm wrapper printed its banner and exited 0
|
||||
# immediately, so the dev server never came up.
|
||||
CMD ["node", "node_modules/vite/bin/vite.js", "--host"]
|
||||
|
||||
# --- Build stage ---
|
||||
# No VITE_API_URL build arg: the production image uses runtime config (/config.js)
|
||||
|
||||
@@ -11,6 +11,12 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
server: {
|
||||
// Bind-mounted source on Docker Desktop (Windows/macOS) does not deliver
|
||||
// inotify events, so Vite never sees host edits and silently serves stale
|
||||
// modules. Polling is opt-in via the compose file so native dev is unaffected.
|
||||
watch: process.env.VITE_USE_POLLING
|
||||
? { usePolling: true, interval: 300 }
|
||||
: undefined,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:3000',
|
||||
|
||||
Reference in new issue
Block a user