我正在使用云函数来呈现一个 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] 删除。
我来说两句