更改 jade 总是需要 node.js 重启然后才能验证更改 [英] change jade always require node.js restart then can verify the change

查看:29
本文介绍了更改 jade 总是需要 node.js 重启然后才能验证更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 node.js 中使用 Jade 作为模板引擎.每当我对 Jade 文件进行更改时,我都必须停止 node.js 并启动,以便验证更改.有没有工具或方法,如果我对 Jade 进行了更改,我不需要重新启动 node.js 应用程序?

I'm using Jade as template engine at node.js. I have to stop node.js and start whenever I made changes to Jade file so I can verified the change. Is there tool or a way that if I made change to Jade I don't need to restart node.js app?

推荐答案

在重新加载页面后,至少在开发模式下,应该自动获取对 Jade 模板的更改.

Changes to Jade templates should be picked up automatically after you reload the page, at least in development mode.

如果不是,那么最可能的原因是在 Express 中启用了视图缓存,如果 NODE_ENV 环境变量设置为 production,这是默认设置,或明确启用缓存.

If not, then the most likely cause is that view caching is enabled in Express, which is the default if the NODE_ENV environment variable is set to production, or caching is explicitly enabled.

要显式禁用视图缓存,您可以使用:

To explicitly disable view caching, you can use this:

var app = express();
...
app.set('view cache', false);
...

但是,当您在生产环境中运行时,这会对性能产生影响,因为每个请求都会处理模板文件.因此,您应该真正尝试找出 Express 缓存模板的原因(如前所述,最有可能的罪魁祸首是 NODE_ENV 未为开发环境正确设置).

However, this will carry a performance impact when you're running in production, as the template file will be processed for each request. Therefore, you should really try to find out why exactly Express is caching your templates (as said, the most likely culprit is NODE_ENV not being set correctly for a development environment).

这篇关于更改 jade 总是需要 node.js 重启然后才能验证更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆