我已经设法让Nunjucks使用Sails.js,但是在我重新启动服务器之前,这些更改似乎是不会被发现的。我将自动看到一两次反映的更改,但在此之后,即使手动刷新浏览器也不会显示我的更改。
我在这里使用以下建议实现了LiveReload:
Get livereload to work with Sails.js
但我不认为这是LiveReload的问题。
有没有其他人让Sails.js和Nunjucks在一起玩得很好?如果是这样的话,是怎么做的?
发布于 2016-03-12 09:52:38
问题在于修女本身。它有一个默认设置为false的watch选项:
您可以在sails/config/bootstrap.js中启用它
var nunjucks = require('nunjucks')
module.exports.bootstrap = function(cb) {
nunjucks.configure({
watch:true
})
// It's very important to trigger this callback method when you are finished
// with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap)
cb();
};与livereload相结合,一切都很好。
发布于 2016-08-21 15:30:46
in /config/views.js
engine: {
ext: 'html',
fn: function (str, options, fn) {
var engine = require('nunjucks');
engine.configure('views', {
autoescape : true,
throwOnUndefined : true,
trimBlocks : true,
lstripBlocks : true,
express : sails.hooks.http.app,
watch : true,
noCache : false,
web : {
useCache : true,
async : false
}
});
engine.render(str, options, fn);
}
},发布于 2019-09-05 17:20:25
对于Sails.js 1,解决方案略有改变:
In /config/views.js
module.exports.views = {
...
getRenderFn: () => {
// Import nunjucks.
const nunjucks = require('nunjucks');
// Configure nunjucks.
const env = nunjucks.configure('views', {
autoescape : false,
throwOnUndefined : true,
trimBlocks : true,
lstripBlocks : true,
watch : true,
noCache : false,
web : {
useCache : true,
async : false
}
});
// Here you can add filter
env.addFilter('filtername', (name) => {
return name;
});
return nunjucks.render;
}
}希望这会对某人有所帮助;)
https://stackoverflow.com/questions/34132055
复制相似问题