Localhost static website development environment with live reload using Webpack 5
10K+
Docker-based local development environment for static HTML, CSS, and JavaScript websites with live reload using Webpack 5 (webpack-dev-server).
This image is only for local development purposes.
A simpler alternative that also serves plain HTML, CSS, and JavaScript files with live reload with optional Sass support for local development is available at
https://hub.docker.com/r/weaponsforge/livereload-basic
Are you using VSCode and want to do live reload but do not want to run livereload-webpack using Docker?
Live Server might be the tool for you. Check it out from the Visual Studio Marketplace.
GitHub Repository
https://github.com/weaponsforge/livereload-webpack
Live Preview (Sample Website)
https://weaponsforge.github.io/livereload-webpack/
docker run commands below run in the foreground.Set up local static website development files following the Webpack project structure. At the very least, it requires having a root project directory with a Webpack-compatible "/src" directory consisting of:
my-website-project/
└── src/
├── index.html
├── index.js
└── ...
From the project directory, run:
# On Linux OS
docker run --rm -p 8080:8080 -v $(pwd)/src:/opt/app/src weaponsforge/livereload-webpack
# On Windows OS
docker run --rm -p 8080:8080 -v %cd%\src:/opt/app/src -e WATCHPACK_POLLING=true weaponsforge/livereload-webpack
WATCHPACK_POLLING=trueis set on Windows because Docker Desktop on Windows doesn't reliably forward native filesystem change events into the container, so Webpack falls back to polling for file changes required for hot reload.
Load the localhost website at http://localhost:8080.
Changes to files in
"src"are automatically reflected in the browser.
To explicitly pull the latest image:
docker pull weaponsforge/livereload-webpack:latest
To stop the container, press Ctrl+C in the terminal it's running in. Since it's started with --rm, it's removed automatically on stop.
Mount the dist directory when starting the container.
# On Linux OS
docker run --rm -p 8080:8080 -v $(pwd)/src:/opt/app/src -v $(pwd)/dist:/opt/app/dist --name weaponsforge-localhost-webpack weaponsforge/livereload-webpack
# On Windows OS
docker run --rm -p 8080:8080 -v %cd%\src:/opt/app/src -v %cd%\dist:/opt/app/dist --name weaponsforge-localhost-webpack -e WATCHPACK_POLLING=true weaponsforge/livereload-webpack
In a separate terminal, build the website:
docker exec weaponsforge-localhost-webpack npm run build
The generated files are available in the host dist directory.
⚠️ NOTE: Stop any previously running container named
"weaponsforge-localhost-webpack"(e.g. one started in the Development or Preview section) before running the command above, ordocker runwill fail with a "name already in use" error.
To preview the bundled website using the Express server, expose port 3000 when starting the container.
# On Linux OS
docker run --rm -p 8080:8080 -p 3000:3000 -v $(pwd)/src:/opt/app/src -v $(pwd)/dist:/opt/app/dist --name weaponsforge-localhost-webpack weaponsforge/livereload-webpack
# On Windows OS
docker run --rm -p 8080:8080 -p 3000:3000 -v %cd%\src:/opt/app/src -v %cd%\dist:/opt/app/dist --name weaponsforge-localhost-webpack -e WATCHPACK_POLLING=true weaponsforge/livereload-webpack
⚠️ NOTE: As above, stop any previously running container named
"weaponsforge-localhost-webpack"before running this command.
In a separate terminal, build and start the Express server:
docker exec weaponsforge-localhost-webpack npm run build
docker exec weaponsforge-localhost-webpack npm start
Open http://localhost:3000 to preview the bundled website.
Content type
Image
Digest
sha256:2f7b00b1e…
Size
65.5 MB
Last updated
about 1 month ago
docker pull weaponsforge/livereload-webpack