Created
November 3, 2015 22:32
-
-
Save smashercosmo/3e9e7a4d1fe82a816bc7 to your computer and use it in GitHub Desktop.
Server hot reload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import imports from './imports'; // <-- all your imports | |
import express from 'express'; | |
const app = express(); | |
if (__DEVELOPMENT__) require('./serverHotReload')(app, () => { | |
try { | |
imports = require('./imports'); | |
} catch (error) { | |
console.log(error.stack) | |
} | |
}); | |
app.use(imports.something); | |
app.use(imports.something2); | |
app.use(imports.something3); | |
app.listen(8000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import chokidar from 'chokidar'; | |
export default function (callback) { | |
const watcher = chokidar.watch('./'); | |
watcher.on('ready', () => { | |
watcher.on('all', () => { | |
console.log("Clearing /server/ module cache from server"); | |
Object.keys(require.cache).forEach(id => { | |
if (/\/server\//.test(id)) delete require.cache[id]; | |
}); | |
callback(); | |
}); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment