Comments (6)
Got it thank you @glenjamin. My mistake was to register the middleware straight (I did the require, then app.use
) instead of wrapping the require into a function inside app.use
like you did). I will close the issue, may that help someone else! Thanks again.
from ultimate-hot-reloading-example.
The other part that makes it work is doing a require
inside the main HTTP handler. Can you post a sample?
from ultimate-hot-reloading-example.
I have added that in the server part:
const watcher = chokidar.watch(`${__dirname}/..`);
watcher.on('ready', function() {
watcher.on('all', function() {
console.log('Clearing /server/ module cache from server');
Object.keys(require.cache).forEach(function(id) {
if (/[\/\\]server[\/\\]/.test(id) && !(/[\/\\]bin[\/\\]/.test(id)) && !(/[\/\\]models[\/\\]/.test(id))) {
console.log('delete', id)
delete require.cache[id]
require(id)
}
});
});
});
=> I exclude the bin folder where the server is located, also the models, because mongoose complains when the model is recreated twice, fair enough.
I have also added explicitly a require(id) after deleting from the cache, otherwise the next time it's run, somehow, the modules are not required again (could be already one problem why I need to do that...)
I should mention I'm using babel with babel-register and ES6 import/export. I've seen, they are somehow caching modules too http://babeljs.io/docs/usage/require/, but I've disabled the cache like mentioned (I have also tried to delete the json file created to force a refresh). Both options didn't change anything.
Below is the structure of the server folder where we can see the bin folder and models folder (both ignored):
For my tests, I changed the value in the console.log and then refreshed the browser to trigger the route. The value shown in the console is (of course) correct the first time the app is started, but not for any subsequent edit to the console.log.
from ultimate-hot-reloading-example.
I think doing the require(id)
inside that loop isn't going to work, as you'll be partially repopulating the cache as you're clearing it.
You need to clear it out entirely, and let the next incoming route repopulate it.
from ultimate-hot-reloading-example.
You're right. I could narrow down the issue to app.use. Something modified outside of Koa feels like to work, but not in Koa. In your version, the middleware is somehow overwritten, but not in my app where even so I do a new app.use with the fresh route, it still keep the previous version. Will try to see/figure out how to deregister/update a middleware...
from ultimate-hot-reloading-example.
Here: https://github.com/glenjamin/ultimate-hot-reloading-example/blob/master/server.js#L28-L31
The middleware here delegates to the real middleware which is "late bound", it always requires the real middleware and passes all the arguments through.
You'll need something like that.
from ultimate-hot-reloading-example.
Related Issues (20)
- Has any example about many components and pages? HOT 2
- PostCSS Not Being Used? HOT 3
- server reload can not work on windows HOT 6
- Mysterious babel error HOT 6
- Flash of style on start up HOT 6
- Express routes not reloading HOT 7
- Is this deprecated? HOT 2
- Issue when converting to ES6 Module syntax HOT 5
- Sass live reload? HOT 1
- Mongoose bug: schema already defined HOT 3
- Consider isomorphic-webpack
- This isn't hot reloading. This is going to the browser and refreshing HOT 1
- How we can use this trick with sass files? HOT 1
- Example with Webpack 2.X
- Integrate VSCode debugging for both client and server side
- npm run start fails on Debian 9
- Figure out exactly what file has been changed instead of clear all cache HOT 2
- Cannot "hot-reload" for the server side/express related stuffs
- Webpack 4?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ultimate-hot-reloading-example.