如何使打字稿传输 .pug 文件到编译目录

马库斯·加列戈斯

我正在使用云函数来呈现一个 html 文件,以便使用 pug 模板引擎通过电子邮件发送。

首先,我正在尝试执行以下操作:

import * as functions from 'firebase-functions';
import * as pug from 'pug';

export const renderHTML = functions.https.onRequest(() => {
// Compile the source code
const compiledFunction = pug.compileFile('email.pug');

// Render a set of data
return compiledFunction({
  name: 'Timothy'
});
// "<p>Timothy's Pug source code!</p>"
});

但是,在运行该函数时,找不到 .pug。我怀疑这是因为它没有在打字稿编译到 js 中结转。那么,如何在不手动将其放入 lib 文件的情况下将其放入该文件中呢?

在此处输入图片说明

道格史蒂文森

将 email.pug 放在函数文件夹中,而不是 src 文件夹中。文件路径相对于部署根,即函数。您可以使用其他文件夹,只要您相对于函数指定它们即可。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章