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

问题描述 投票:0回答:1

[我正在使用云函数来呈现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文件的情况下将其放入lib文件中?

enter image description here

typescript firebase google-cloud-functions pug
1个回答
0
投票

将email.pug放置在functions文件夹中,而不是src文件夹中。文件路径是相对于部署根目录(即功能)而言的。您可以使用其他文件夹,只要您相对于功能指定它们即可。

© www.soinside.com 2019 - 2024. All rights reserved.