Skip to content

Instantly share code, notes, and snippets.

@smashercosmo
Created November 3, 2015 22:32
Show Gist options
  • Save smashercosmo/3e9e7a4d1fe82a816bc7 to your computer and use it in GitHub Desktop.
Save smashercosmo/3e9e7a4d1fe82a816bc7 to your computer and use it in GitHub Desktop.
Server hot reload
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);
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