是否有一个模板软件包,可以用快递模板渲染进行操作



我已经尝试过(并且失败(将3种不同的模板软件包与节点/express一起使用。(模具,模版JS,@Stencil(。特别是,我正在寻找一个可以让我进行标准的Express模板渲染的软件包,例如:

npm install stencil
.
.
app.engine('stencil', require('stencil').renderFile);
app.set('view engine', 'stencil');
.
.
app.get('/', function(req, res, next) {
    // Where 'somepage' is /views/somepage.stencil
    res.render('somepage', { title: 'Stencil Test' });
});

我尝试过的软件包似乎是出于其他目的,即没有render函数和/或您将与App.Engine((函数一起使用的回调方法。我可能忽略了显而易见的模具似乎很受欢迎(Kitura等(,并且似乎很自然地适合Express。

hmm,您所说的话,也许您正在寻找SSR(服务器端渲染(?

您有一个有关如何使用Express

在服务器上渲染页面的示例
const express = require('express');
const stencil = require('@stencil/core/server');
// create the express app
const app = express();
// load the stencil config and
// express serve-side rendering middleware
const { wwwDir, logger } = stencil.initApp({
  app: app,
  configPath: __dirname
});
// serve static files
app.use(express.static(wwwDir));
// set which port express it will be listening on
const port = 3030;
// start listening and handling requests
app.listen(port, () => logger.info(`server-side rendering listening on port: ${ port }`));

您可以在此处找到有关SSR的更多信息

最新更新