node.js - 在express中禁用pug(jade)模板的 View 缓存

标签 node.js express pug

我使用"express": "^4.14.0", "pug": "^2.0.0-beta6"

app.set('view engine', 'jade');
...
app.get('/', function (req, res) {
    res.render('index.pug', {...});
}

当我使用 Express render 函数时,它仅渲染模板一次。如果我更改 pug-template,我将获得基于已编译模板的旧页面版本。出于开发目的,我需要为每个 render 调用快速重新编译 .pug 模板。我怎样才能实现这个目标?

我尝试过类似的方法:

app.disable('view cache'); OR
app.set('view cache', false); OR
app.set('view cache', 'disabled');

但这些都没有帮助。

最佳答案

令人失望,但工作:

const pug = require('pug');
const path = require('path');
res.send(pug.renderFile(path.join(__dirname,'template.pug'), templateObj));

关于node.js - 在express中禁用pug(jade)模板的 View 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41073026/

相关文章:

javascript - 在jade中一键点击运行两个javascript函数

node.js - npm 命令不工作/响应

javascript - 如何删除 Mongoose 中带有引用集合的集合?

MySQL 回调和范围

javascript - 如何从 Javascript 调用 Jade 文件中的函数

javascript - 单击按钮时调用 Jade mixin 函数

javascript - Javascript 中的 try...catch 中出现异常

node.js - NodeJS 和 AWS Lambda 的异步等待问题

node.js - Nodejs/Express POST 请求中间件无法在回调中调用 next()

angularjs - 部署在云服务器上时使用 localhost 地址进行 $http.get 请求