I found myself in the same situation, coincidentally, mail templates as well. It took me a while to figure this out, but Typescript will absolutely do nothing for you here, you have to fix this outside of Typescript.
You'll also want to use a OS-independent way; most answers thusfar are OS specific (nice until you're moving to production), or are for NestJs.
The solution lies in two npm packages (DEV dependencies):
- rimraf (to clean-up)
- copyfiles (to copy files)
Using your preferred package manager:
pnpm add -D rimraf copyfiles
npm install --save-dev rimraf copyfiles
yarn add -D rimraf copyfiles
Then add two "scripts" to your package.json. In my project the target folder is called "build"
, yours might be called "dist"
, adjust as needed. Also, this assumes the "templates" folder is in your "src" folder, it could also be in your projects root, again adjust as needed.
"scripts": {
...
"clean": "rimraf build/",
"copyfiles": "copyfiles -u 1 src/templates/**/* build/"
},
At this point, you can test both commands. Using pnpm (I'm sure you can imagine the command for other managers):
pnpm copy-files
pnpm clean
If this worked, you can then go ahead and change your build script, adding the clean step before it, and the copy step after it. Work with your existing build script. In my case it was just calling tsc
. Which would then look like:
"scripts": {
...
"clean": "rimraf build/",
"copyfiles": "copyfiles -u 1 src/templates/**/* build/",
"build": "pnpm clean && tsc && pnpm copyfiles"
}
Documentation:
"assets":["**/Mail/templates/*"]
should be placed insidecompilerOptions
object – Near