【问题标题】:Disable view cache for pug (jade) templates in express在 express 中禁用 pug (jade) 模板的视图缓存
【发布时间】:2016-12-10 06:56:36
【问题描述】:

我用"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');

但这些都没有帮助。

【问题讨论】:

    标签: node.js express pug


    【解决方案1】:

    令人失望,但工作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 2013-04-17
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      • 1970-01-01
      • 2011-06-26
      相关资源
      最近更新 更多