Skip to content

Commit 6db3ccc

Browse files
committed
feat: enable live reload
* in container running in windows host
1 parent 44d3edf commit 6db3ccc

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

docker-compose.dev.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ services:
1212
ports:
1313
- "3000:3000"
1414
- "9229:9229"
15-
15+
# Enable USE_POLLING if working in Windows WSL2 to enable hot reload
16+
environment:
17+
- IS_DOCKER=true
18+
# - USE_POLLING=true

docker-compose.prod.yml

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ services:
88
target: production
99
volumes:
1010
- .:/opt/app
11+
- /opt/app/node_modules
1112
ports:
1213
- "3000:3000"

gulpfile.js

+38-24
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
1-
const gulp = require('gulp')
2-
const browserSync = require('browser-sync').create()
3-
const root = './public'
4-
const PORT = process.env.PORT || 3000
5-
6-
// browsersync local static server
7-
const server = function () {
8-
browserSync.init({
9-
server: root,
10-
port: PORT
11-
})
12-
}
13-
14-
// Files to watch for changes then reload browser
15-
const watch = function () {
16-
gulp.watch(`${root}/*.html`).on('change', browserSync.reload)
17-
gulp.watch(`${root}/*.css`).on('change', browserSync.reload)
18-
gulp.watch(`${root}/*.js`).on('change', browserSync.reload)
19-
}
20-
21-
// Gulp tasks
22-
gulp.task('browserSync', server)
23-
gulp.task('watch', watch)
24-
gulp.task('dev', gulp.series(gulp.parallel('browserSync', 'watch')))
1+
const gulp = require('gulp')
2+
const browserSync = require('browser-sync').create()
3+
const root = 'public'
4+
const PORT = process.env.PORT || 3000
5+
6+
// browsersync local static server
7+
const server = function () {
8+
browserSync.init({
9+
server: root,
10+
port: PORT,
11+
...(process.env.IS_DOCKER && { open: false })
12+
})
13+
}
14+
15+
// Files to watch for changes then reload browser
16+
const watch = function () {
17+
const html = `${root}/**/*.html`
18+
const css = `${root}/**/*.css`
19+
const js = `${root}/**/*.js`
20+
21+
// Use gulp internal and polling if working in Windows WSL2 to enable hot reload
22+
gulp.watch(html,
23+
(process.env.USE_POLLING && { interval: 1000, usePolling: true })
24+
).on('change', browserSync.reload)
25+
26+
gulp.watch(css,
27+
(process.env.USE_POLLING && { interval: 1000, usePolling: true })
28+
).on('change', browserSync.reload)
29+
30+
gulp.watch(js,
31+
(process.env.USE_POLLING && { interval: 1000, usePolling: true })
32+
).on('change', browserSync.reload)
33+
}
34+
35+
// Gulp tasks
36+
gulp.task('browserSync', server)
37+
gulp.task('watch', watch)
38+
gulp.task('dev', gulp.series(gulp.parallel('browserSync', 'watch')))

0 commit comments

Comments
 (0)