I have solved this issue, but wanted to document it for others.
I had a TypeScript project using the Serverless Framework. I reached a point in the project where I wanted to use EJS templates for composing emails. The implementation worked locally, but I realized that the lambda was failing because the EJS files were not being included in the compiled build.
I tried solving the problem by importing the file (instead of using fs
), but then that lead me into a days long journey reworking my build workflow, trying to incorporate Webpack, which just kept bringing up new issues to solve.
Eventually, I came upon a section of the Serverless docs concerning excluding and including files. It may have just been me, but I got the impression that the include
config was just for reversing sections of things mentioned in the exclude
. Because of this, I dismissed it at first, but decided to try it out and thankfully, it solved my problem.
The result of a TypeScript build will only include the files it compiles, and accompanying dependencies. The way to have Serverless include files not compiled by TypeScript in the build result is to use the include
configuration.
For this specific example, a solution with a glob pattern to include all EJS files under the src folder would look like this:
serverless.yml
package:
include:
- src/**/*.ejs