如何在Express中输出漂亮的html? [英] How to output pretty html in Express?
问题描述
如何获得打印好的格式化HTML?
在你的主要 app.js
或它的地方是什么:
Express 4.x
if(app.get('env')==='development'){
app .locals.pretty = true;
}
Express 3.x
app.configure('development',function(){
app.use(express.errorHandler());
app.locals.pretty = true;
});
Express 2.x
app.configure('development',function(){
app.use(express.errorHandler());
app.set('查看选项',{pretty:true});
});
我把这个漂亮的打印放在开发
中,因为您将需要在生产
中使用丑来提高效率。在生产中部署时,请确保设置环境变量 NODE_ENV = production
。这可以在 sh
脚本中使用,您在 package.json
的脚本字段中使用并执行启动。
Express 3 已更改,因为:
视图选项设置已不再需要,应用程序。本地人是与res.render()的合并的局部变量,所以[app.locals.pretty = true与传递res.render(view,{pretty:true})相同。
I've noticed that while using Express for Node.js, it outputs the html code without any newline characters or tabs. It's not very pretty, although it could technically be more efficient for downloading.
How could I get it to print nice formatted html?
In your main app.js
or what is in it's place:
Express 4.x
if (app.get('env') === 'development') {
app.locals.pretty = true;
}
Express 3.x
app.configure('development', function(){
app.use(express.errorHandler());
app.locals.pretty = true;
});
Express 2.x
app.configure('development', function(){
app.use(express.errorHandler());
app.set('view options', { pretty: true });
});
I put the pretty print in development
because you'll want more efficiency with the 'ugly' in production
. Make sure to set environment variable NODE_ENV=production
when you're deploying in production. This can be done with an sh
script you use in the 'script' field of package.json
and executed to start.
Express 3 changed this because:
The "view options" setting is no longer necessary, app.locals are the local variables merged with res.render()'s, so [app.locals.pretty = true is the same as passing res.render(view, { pretty: true }).
这篇关于如何在Express中输出漂亮的html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!