Express 集成(Express Integration)
¥Express Integration
Pug 与流行的 Node.js Web 框架 Express 完全集成,作为受支持的视图引擎。查看 Express 优秀的 guide,了解如何将 Pug 与 Express 集成。
¥Pug fully integrates with Express, a popular Node.js web framework, as a supported view engine. Check out Express’s excellent guide for how to integrate Pug with Express.
生产默认值(Production Defaults)
¥Production Defaults
在 Express 中,环境变量 NODE_ENV
旨在告知 Web 应用执行环境:无论是在开发中还是在生产中。Express 和 Pug 会自动修改生产环境中一些选项的默认值,为用户提供更好的开箱即用体验。
¥In Express, the environmental variable NODE_ENV
is designed to inform the web application of the execution environment: whether it is in development or in production. Express and Pug automatically modify the defaults of a few options in production environment, to provide a better out-of-the-box experience for users.
具体来说,当 process.env.NODE_ENV
设置为 'production'
,并且 Pug 与 Express 一起使用时,compileDebug
选项默认为 false
,而 cache
选项默认为 true
。
¥Specifically, when process.env.NODE_ENV
is set to 'production'
, and Pug is used with Express, the compileDebug
option is false
by default, while the cache
option is true
.
要覆盖 compileDebug
和 cache
的默认值,你可以将 app.locals
或 res.locals
对象中的相应属性设置为 true
或 false
。cache
选项也可以通过 Express 的 app.disable
/enable('view cache')
覆盖。
¥To override the defaults for compileDebug
and cache
, you can set the respective property in app.locals
or res.locals
objects to true
or false
. The cache
option can also be overriden through Express’s app.disable
/enable('view cache')
.
欲了解更多详情,请查看 Express 的 API 参考。
¥For more details, check Express’s API reference.