0

I have the following Firebase function which uses nodemailer to send an email with attachment.

    await nodemailer.createTransport(transport).sendMail({
        from: from,
        to: studentDto.email,
        subject: subject,
        html: Mail.createInvoice(studentDto, itemDto),
        attachments: [{filename: 'file.pdf', path: './assets/file.pdf'}],
    });

The PDF is at src/assets/file.pdf. When I run npm run build the folder lib is created but assets/file.pdf is not included.

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

How can file.pdf be included in the build?

Ero Stefano
  • 556
  • 2
  • 9
  • 27
  • 1
    Does this answer your question? [How to copy non-ts files to dist when building typescript?](https://stackoverflow.com/questions/60306654/how-to-copy-non-ts-files-to-dist-when-building-typescript) – Inigo Dec 06 '21 at 20:41
  • Thx, it helped me understand the issue. But I found another solution which I will post here. – Ero Stefano Dec 07 '21 at 10:40

1 Answers1

-1

Reason

TSC does not include any assets in the build.

Solution

I uploaded the file to Firebase Storage. There I could copy the public url and use it.

Ero Stefano
  • 556
  • 2
  • 9
  • 27