有没有办法使用 node-dev 或类似的方法来为某些文件切换重启 nodejs?
我已经看过了,似乎 require.extensions 是一个包含要重新启动的扩展名的对象,尽管删除它似乎没有任何作用。
我想要的是能够像往常一样使用node-dev,但是不需要重新启动某些文件,所以我可以手动观看它们并重新加载它们而无需重新启动所有内容。
Hot-(re)loading modules is a hot potato, to say the least. Modules assume that when they are loaded, they are done so into a clean environment, and hot-loading changes that. It opens up for all kinds of scary bugs such as memory leaks and broken memory pointers and is in my honest opinion not worth the hassle. Here's a similar question with a good answer.
Quite relevant to the subject, one of the projects I am working on right now: overseer
It's an experimental cluster manager that wraps your workers and gives you the ability to watch for file system changes and do rolling restarts of the workers (restart them one by one), so there's no experienced downtime.
However, there's currently no way to attach a client to a specific worker, so in a worst case scenario the client will be dealing with two or more workers that are running different versions of your app. Not the most ideal of situations :)