Simple localhost static website development environment for plain HTML, CSS, and JavaScript files with live reload.
Its development static hosting and file-serving architecture are closer to traditional static web servers. Uses Gulp and Browser-Sync
Note
An alternate localhost static development environment using Webpack, also with live reload, is available at
https://github.com/weaponsforge/livereload-webpack
Tip
Are you using VSCode and want to do live reload but do not want to install livereload-basic's Node dependencies or run it using Docker? Live Server might be the tool for you. Check it out from from the Visual Studio Marketplace.
- Dependencies
- Installation
- Usage
- Available Scripts
- Usage with Docker
- Building Docker Images
- Deployment with GitHub Actions
- Deployment URLs
- Debugging Notes
- References
The following dependecies are used for this project. Feel free to experiment using other dependencies and versions.
- Windows 64-bit OS
- nvm version 1.1.12 (for Windows)
- NodeJS 16.14.2 installed using nvm
- node v20.15.0
- npm v10.7.0
- yarn v1.22.22
- installed using NodeJS
- NodeJS modules (installed using yarn)
- gulp v5.0.0
- browser-sync v3.0.3
-
Clone this repository.
https://github.com/weaponsforge/livereload-basic.git
-
Install dependencies.
yarn install
These steps use Node and Yarn to run the development app.
-
Run the localhost static website development environment.
yarn dev
-
Edit the existing static files from the ./public directory and wait for live reload. Your updates will reflect on the web browser.
-
To include new static website files on live reload:
- Create new static (.html, .js, .css) files inside the ./public directory.
- Refresh the web browser.
- Restart the web server if updates don't show after a while.
yarn dev
-
Run the production static website (does not use live reload).
yarn start
Runs the Gulp and Browser-Sync tasks, launching the local website for development mode.
Sets the IS_DOCKER=true
environment variable before running the Gulp and Browser-Sync tasks inside a Docker container. It doesn't launch the local website for development mode.
This command runs only in a Linux environment.
Runs a simple ExpressJS web server serving the static website app using its static middleware.
This project deploys the latest development Docker image to Docker Hub on the creation of new Release/Tags. It is available at:
https://hub.docker.com/r/weaponsforge/livereload-basic
-
Pull the pre-built development Docker image using any of the two (2) options:
- Open a terminal and run:
docker pull weaponsforge/livereload-basic:latest
- Navigate to the livereload-basic root project directory, then run:
docker compose -f docker-compose.dev.yml pull
- Open a terminal and run:
-
Run the development image.
-
Using only Docker (1st option):
INFO: This option requires having the static website development HTML, CSS, and JavaScript files inside a
FILE_DIRECTORY
directory in the host machine. This example uses aFILE_DIRECTORY
named"/public"
, which contains at least:├─ my-website-project │ ├─ public │ ├─── index.html │ ├─── ...
Navigate to the root project directory (for example,
"my-website-project"
) using a terminal, then run:# On Linux OS docker run -it --rm -p 3000:3000 -v $(pwd)/FILE_DIRECTORY:/opt/app/public weaponsforge/livereload-basic:latest # On Windows OS docker run -it --rm -p 3000:3000 -v %cd%\FILE_DIRECTORY:/opt/app/public -e USE_POLLING=true weaponsforge/livereload-basic:latest
TIP:
Replace-p 3000:3000
with other port bindings as needed. -
Using Docker compose (2nd option):
docker compose -f docker-compose.dev.yml up
-
INFO: Uncomment the following lines in the
docker-compose.dev.yml
file when working in a Windows host.# Enable USE_POLLING if working in Windows WSL2 to enable live reload environment: - USE_POLLING=true
-
-
Refer to the Usage section steps # 2 - # 4 for local development.
-
Build the Docker image for local development.
docker compose -f docker-compose.dev.yml build
INFO: Do this step only once or after installing new packages in the package.json file.
- Refer to the Development Image section for more information.
-
Run the development image.
docker compose -f docker-compose.dev.yml up
-
Refer to the Usage section steps # 2 - # 3 for local development.
-
Stop and exit the development container.
docker compose -f docker-compose.dev.yml down
The development Docker image contains Node runtime, Gulp, Browser-Sync and Yarn dependencies, and the latest repository source codes for local development. Build it with:
docker compose -f docker-compose.dev.yml build
The production Docker image contains the static website running in an nginx container for minimal production website build. Build it with:
docker compose -f docker-compose.prod.yml build
This repository deploys the local development Docker image to Docker Hub on the creation of new Release/Tags.
Add the following GitHub Secrets and Variables to enable deployment to Docker Hub.
GitHub Secret | Description |
---|---|
DOCKERHUB_USERNAME | (Optional) Docker Hub username. Required to enable pushing the development image to Docker Hub. |
DOCKERHUB_TOKEN | (Optional) Deploy token for the Docker Hub account. Required to enable pushing the development image to Docker Hub. |
GitHub Variable | Description |
---|---|
DOCKERHUB_USERNAME | (Optional) Docker Hub username. Required to enable pushing the development image to Docker Hub. |
Docker Hub
https://hub.docker.com/r/weaponsforge/livereload-basic
Live Preview (Sample Website)
https://weaponsforge.github.io/livereload-basic/
Debugging Traditional Web Apps in VSCode
Debugging regular (traditional) web apps with VSCode is similar to debugging and adding breakpoints from the Chrome or Edge browser's Sources tab.
TIP
Take note of its VSCode launch settings with a"pathMapping"
key. It is quite similar to the VSCode launch settings of web apps launched with Webpack.
-
Add breakpoints in the JavaScript (
*.js
) files inside the website's directory entry point at the"public/"
directory. -
Copy the following VSCode launch configurations to the
/.vscode/launch.json
file'sconfigurations[]
array:Debug with MS Edge
{ "name": "Debug Regular App in Edge", "request": "launch", "type": "msedge", "url": "http://localhost:3000", "pathMapping": { "/": "${workspaceFolder}/public", } }
Debug with Chrome
{ "name": "Debug Regular App in Chrome", "request": "launch", "type": "chrome", "url": "http://localhost:3000", "pathMapping": { "/": "${workspaceFolder}/public", } }
-
Run the app using Node or from a container.
-
Select a debugger to run in VSCode. Press
Ctrl + Shift + D
- Select
"Debug Regular App in Edge"
to launch an Edge web browser. - Select
"Debug Regular App in Chrome"
to launch a Chrome web browser.
- Select
-
Run and use the app from the launched browser instance on step # 4.
[1] - live reload using gulp v.3.9.1 (older gulp version)
[2] - gulp notes (trello)
@weaponsforge
20200630
20241008