ashwanikumarjha
Fri Jan 19 2024
In a web app, certain non-code files like EJS templates are not automatically included in the production build, causing runtime errors as the application can't locate these files.
NestJS provides a built-in solution through the nest-cli.json
configuration file. This file allows us to specify non-TypeScript assets to be included in the build process. By defining a pattern for the files and specifying the output directory, we can ensure these files are copied to the correct location during the build process.
Example nest-cli.json
:
{
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"assets": [
{ "include": "emails/templates/*.ejs", "outDir": "dist/src" }
],
"watchAssets": true
}
}
In frameworks that do not provide a built-in solution for including non-TypeScript files in the build process, we can use external tools to handle this. For example, in Hapi.js, we can use cpx
to copy these files during the build process.