Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed unreliable hot reloading #29

Merged
merged 2 commits into from
Aug 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 15 additions & 12 deletions lib/listening.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Native
const path = require('path')
const debounce = require('debounce')

// Packages
const { write: copy } = require('clipboardy')
Expand Down Expand Up @@ -76,7 +77,6 @@ module.exports = async (server, inUse, flags, sockets) => {
const watchConfig = {
usePolling: flags.poll,
ignoreInitial: true,
cwd: process.cwd(),
ignored: [
/\.git|node_modules|\.nyc_output|\.sass-cache|coverage/,
/\.swp$/
Expand All @@ -102,21 +102,24 @@ module.exports = async (server, inUse, flags, sockets) => {
const watcher = watch(toWatch, watchConfig)

// Ensure that the server gets restarted if a file changes
watcher.on('all', (event, filePath) => {
const location = path.relative(process.cwd(), filePath)
watcher.on(
'all',
debounce((event, filePath) => {
const location = path.relative(process.cwd(), filePath)

console.log(
`\n${chalk.blue('File changed:')} ${location} - Restarting server...`
)
console.log(
`\n${chalk.blue('File changed:')} ${location} - Restarting server...`
)

destroySockets(sockets)
destroySockets(sockets)

// Ensure the same port when restarting server
flags.port = details.port
// Ensure the same port when restarting server
flags.port = details.port

// Restart server
server.close(restartServer.bind(this, file, flags, watcher))
})
// Restart server
server.close(restartServer.bind(this, file, flags, watcher))
}, 10)
)
}

if (flags.restarted) {
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"chalk": "2.1.0",
"chokidar": "1.7.0",
"clipboardy": "1.1.4",
"debounce": "1.0.2",
"get-port": "3.1.0",
"ip": "1.1.5",
"jsome": "2.3.26",
Expand Down