Skip to content

Commit

Permalink
fix: hot reload in docker development by using polling & correct workdir
Browse files Browse the repository at this point in the history
WATCHPACK_POLLING is enabled by default to use file change polling so
hot reload works more easily out-of-the-box

Tested and hot reload worked on Windows 11 + Docker Desktop + WSL2
using "docker compose up --build" and keeping the source code on the
host's NTFS file system, not inside the Linux file system in WSL2.

refs PT-1792
  • Loading branch information
karisal-anders committed Oct 29, 2024
1 parent 686a5fb commit 2381b2d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ FROM appbase AS development
ARG NODE_ENV=development
ENV NODE_ENV $NODE_ENV

# Enable hot reload by default by polling for file changes.
#
# NOTE: Can be disabled by setting WATCHPACK_POLLING=false in file `.env`
# if hot reload works on your system without polling to save CPU time.
ARG WATCHPACK_POLLING=true
ENV WATCHPACK_POLLING=${WATCHPACK_POLLING}

WORKDIR /app

# copy in our source code last, as it changes the most
COPY --chown=default:root . .

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ services:
build:
context: .
target: ${DOCKER_TARGET:-development}
environment:
- WATCHPACK_POLLING=${WATCHPACK_POLLING:-true}
volumes:
# Share local directory to enable development with hot reloading
- .:/app
Expand Down
7 changes: 7 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ module.exports = {
};
}

// https://webpack.js.org/configuration/watch/#watchoptions
config.watchOptions = {
poll: 1000, // Check for changes every second
aggregateTimeout: 300, // Delay 0.3s before rebuilding to group changes
ignored: ['**/node_modules'],
};

config.resolve.alias = {
...config.resolve.alias,
'~hds-core': path.resolve(__dirname, './node_modules/hds-core'),
Expand Down

0 comments on commit 2381b2d

Please sign in to comment.