【问题标题】:How to make typescript transfer .pug file to compiled directory如何使打字稿传输.pug文件到编译目录
【发布时间】:2020-05-21 00:59:41
【问题描述】:

我正在使用云函数来渲染一个 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。我怀疑这是因为它没有在 typescript 编译到 js 时结转。那么,如何在不手动将其放入 lib 文件的情况下将其放入 lib 文件中呢?

【问题讨论】:

    标签: typescript firebase google-cloud-functions pug


    【解决方案1】:

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

    【讨论】:

    • 这似乎奏效了。但是...当我运行该功能时,什么都没有发生,只是超时。你看到代码本身有什么问题吗?我认为这应该可行...
    • 我不知道,我建议用你的调试细节发布一个新问题。
    猜你喜欢
    • 1970-01-01
    • 2016-07-05
    • 1970-01-01
    • 2016-04-01
    • 1970-01-01
    • 2020-09-02
    • 2016-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多